You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5bbcd43
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/sap_cloud_sdk/cache/user-guide.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,6 +120,29 @@ The backend interface has exactly four methods and no awareness of tenants, TTL
120
120
121
121
For a real, in-tree example of how the cache is used, see `XsuaaAuthProvider` in `sap_cloud_sdk.core.protocol.http.models`. It uses `IsolationStrategy.TENANT` to cache OAuth2 sessions per tenant, with TTL derived from the token's `expires_in` field and automatic eviction on secret rotation.
122
122
123
+
## Per-Module Shared Backend
124
+
125
+
By default each `Cache` instance gets its own `InMemoryLRUBackend`. That is fine when the same client object is reused across requests, but some modules (e.g. Agent Gateway) create a fresh client on every request. In that case the cache would be empty on each request, defeating its purpose.
126
+
127
+
Pass `module=` to share a single backend across all `Cache` instances that name the same module:
128
+
129
+
```python
130
+
from sap_cloud_sdk.cache._cache import Cache
131
+
from sap_cloud_sdk.cache import CacheConfig, IsolationStrategy
132
+
133
+
# Every time this module creates a new client, it gets the same backend.
The backend is created once (process-scoped, singleton per module name) and reused for the lifetime of the process. Tenant isolation still works normally — the isolation key is derived from the active `RuntimeContext` on every `get`/`set`, so entries are never shared across tenants.
141
+
142
+
### Sizing and eviction
143
+
144
+
`max_size` and `on_evict` are taken from the **first**`Cache` created for a given module name. Later callers with different values are silently ignored. This is intentional: a module uses one sizing policy for its backend.
0 commit comments