feat(cache): add core cache module - #265
Draft
cassiofariasmachado wants to merge 2 commits into
Draft
Conversation
| from sap_cloud_sdk.cache import CacheBackend, CacheConfig, configure_cache | ||
|
|
||
|
|
||
| class MyCacheBackend(CacheBackend): |
Contributor
There was a problem hiding this comment.
I like it to have customization.
Do we know if like redis cache could be inplemented?
Can we also offer a more global configuration at least for Cache class to be used?
| within the same tenant. | ||
| """ | ||
|
|
||
| TENANT = "tenant" |
Contributor
There was a problem hiding this comment.
Is this mandatory? If yes, we would need a provider level.
Contributor
|
Can we implement it in one module to exemplify usage? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
sap_cloud_sdk.cache— a domain-agnostic, pluggable cache layer to be shared across all SDK modules. The module is infrastructure-only: it has no BTP service binding and nocreate_client()factory.Key design decisions follow the cache core strategy spec:
CacheBackendABC — four-method interface (get,set,delete,clear); fully backend-agnostic (no tenant or TTL awareness).InMemoryLRUBackend— default in-process backend backed bycachetools.TTLCache; thread-safe; per-entry TTL via monotonic clock; LRU eviction atmax_size.CacheConfig— dataclass coveringenabled,isolation_strategy,default_ttl_seconds,expiry_buffer_seconds,max_size,backend, andon_evictcallback.configure_cache()/get_cache_config()— global registry set once at startup; per-client override supported viaCacheConfigconstructor argument.IsolationStrategy—TENANT/TENANT_USERenum; auto-selected from context (user ID present →TENANT_USER); SHA-256-based key derivation prevents cross-tenant and cross-user cache hits.Cachefaçade (SDK-internal, not exported) — glues config, isolation, and backend; appliesexpiry_buffer_seconds; isolates backend exceptions.Not in scope for this draft: migrating existing per-module token caches (
adms,agentgateway), Redis backend implementation, destination caching integration.Related Issue
Type of Change
How to Test
uv sync --all-extras --group devuv run pytest tests/cache/ -vChecklist
Breaking Changes
None — this is a purely additive new module.
Additional Notes
cachetools~=5.5.2added to[project.dependencies](MIT licence, already a transitive dependency ofgoogle-authin the ecosystem).Module.CACHE = "cache"added tocore/telemetry/module.py(alphabetical order). No operation constants needed — the cache is infrastructure, not a traced service call.Cachefaçade is intentionally not exported fromsap_cloud_sdk.cache; SDK modules import it directly viafrom sap_cloud_sdk.cache._cache import Cache.