Ce que vous obtenez par défaut
| Durée | En cours | Survivre |
|---|---|---|
| noeud | ~/.iagenify/session, dans un répertoire créé avec le mode 0700 | redémarrer |
| navigateur | localStorage, sous iagenify_session | recharges, par origine |
| travailleur | mémoire | Un seul isolat |
En nœud, sessionPath déplacer le fichier. Partout ailleurs, l'emplacement est fixé, et la façon de le modifier est de fournir votre propre stockage.
Vous fournir les vôtres
Trois méthodes d'async. read renvoie ce qui a été écrit en dernier, ou null; write les entrepose; clear Ça l'enlève.
const api = new IaGenify({
apiKey,
storage: {
storageType: "custom", // reported at exchange; informational
async read() { return JSON.parse((await redis.get(key)) || "null"); },
async write(data) { await redis.set(key, JSON.stringify(data)); },
async clear() { await redis.del(key); },
},
});import json
class RedisSession:
storage_type = "custom" # informational
def read(self): return json.loads(redis.get(key) or "null")
def write(self, data): redis.set(key, json.dumps(data))
def clear(self): redis.delete(key)
api = IaGenify(api_key=api_key, storage=RedisSession())Une première exécution n'a rien stocké. Attrapez la lecture à l'intérieur et retournez null, ou le premier appel échoue au lieu d'échanger la clé.
Un client sans clé du tout
Si votre stockage tient déjà une session, vous pouvez construire un client sans clé. Ne passez ni et le constructeur refuse, en nommant les deux façons.
// Valid: the session comes from the store
const api = new IaGenify({ storage: myStore });
// Refused at construction
new IaGenify({});
// Error: IaGenify requires an API key. Pass { apiKey } or provide a custom
// storage with an existing session.# Valid: the session comes from the store
api = IaGenify(storage=my_store)
# Refused at construction
IaGenify()
# ValueError: IaGenify requires api_key or a custom session storage.Garder les locataires séparés
const clientFor = (tenant) => new IaGenify({
apiKey: keyOf(tenant),
appName: "billing-worker",
storage: {
storageType: "custom",
async read() { return JSON.parse((await kv.get(`sess:${tenant}`)) || "null"); },
async write(data) { await kv.put(`sess:${tenant}`, JSON.stringify(data)); },
async clear() { await kv.delete(`sess:${tenant}`); },
},
});import json
class TenantSession:
def __init__(self, tenant): self.key = f"sess:{tenant}"
def read(self): return json.loads(kv.get(self.key) or "null")
def write(self, data): kv.set(self.key, json.dumps(data))
def clear(self): kv.delete(self.key)
def client_for(tenant):
return IaGenify(api_key=key_of(tenant), app_name="billing-worker", storage=TenantSession(tenant))