Skip to content

feat(cache): add core cache module - #265

Draft
cassiofariasmachado wants to merge 2 commits into
mainfrom
feature/add-cache-core-module
Draft

feat(cache): add core cache module#265
cassiofariasmachado wants to merge 2 commits into
mainfrom
feature/add-cache-core-module

Conversation

@cassiofariasmachado

Copy link
Copy Markdown
Member

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

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 no create_client() factory.

Key design decisions follow the cache core strategy spec:

  • CacheBackend ABC — four-method interface (get, set, delete, clear); fully backend-agnostic (no tenant or TTL awareness).
  • InMemoryLRUBackend — default in-process backend backed by cachetools.TTLCache; thread-safe; per-entry TTL via monotonic clock; LRU eviction at max_size.
  • CacheConfig — dataclass covering enabled, isolation_strategy, default_ttl_seconds, expiry_buffer_seconds, max_size, backend, and on_evict callback.
  • configure_cache() / get_cache_config() — global registry set once at startup; per-client override supported via CacheConfig constructor argument.
  • IsolationStrategyTENANT / TENANT_USER enum; auto-selected from context (user ID present → TENANT_USER); SHA-256-based key derivation prevents cross-tenant and cross-user cache hits.
  • Cache façade (SDK-internal, not exported) — glues config, isolation, and backend; applies expiry_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

  • New feature (non-breaking change that adds functionality)
  • Dependency update

How to Test

  1. Install dependencies: uv sync --all-extras --group dev
  2. Run the cache unit tests: uv run pytest tests/cache/ -v
  3. Run the full lint and type-check suite:
    uv run ruff check src/sap_cloud_sdk/cache/
    uv run ruff format --check src/sap_cloud_sdk/cache/
    uv run ty check src/sap_cloud_sdk/cache/
    
  4. Expected result: 53 tests pass, all checks clean.

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None — this is a purely additive new module.

Additional Notes

  • cachetools~=5.5.2 added to [project.dependencies] (MIT licence, already a transitive dependency of google-auth in the ecosystem).
  • Module.CACHE = "cache" added to core/telemetry/module.py (alphabetical order). No operation constants needed — the cache is infrastructure, not a traced service call.
  • The Cache façade is intentionally not exported from sap_cloud_sdk.cache; SDK modules import it directly via from sap_cloud_sdk.cache._cache import Cache.

from sap_cloud_sdk.cache import CacheBackend, CacheConfig, configure_cache


class MyCacheBackend(CacheBackend):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mandatory? If yes, we would need a provider level.

@NicoleMGomes

Copy link
Copy Markdown
Contributor

Can we implement it in one module to exemplify usage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants