Cache
Cache results you can reconstruct: frequent queries, summaries or expensive calculations. Decide how long a value may become stale and when to invalidate it. The database keeps permanent information; caching avoids repeated work.
First operation from a controller
Section titled “First operation from a controller”The default file store works with the normal Orionis installation. Set these application environment values before startup:
CACHE_STORE=fileCACHE_PREFIX=my-appIts default directory is storage/framework/cache/data; the application process needs write access there. No Redis server or additional Python cache package is needed. Import the facade from orionis.support.facades. Save this controller in app/http/controllers/cache_example_controller.py:
from orionis.http import JSONResponsefrom orionis.support.facades import Cache
class CacheExampleController: async def __call__(self) -> JSONResponse: key = "catalog:summary:v1" await Cache.set(key, {"products": 42}, ttl=300) return JSONResponse(await Cache.get(key))Register its action in the configured route file:
from app.http.controllers.cache_example_controller import CacheExampleControllerfrom orionis.support.facades import Route
Route.get("/cache-example", CacheExampleController)The dictionary is cached for five minutes. Once expired or deleted, get() returns None. To calculate only on a miss, use remember() in the operations guide.
Service architecture
Section titled “Service architecture”flowchart TD accTitle: Accessing the Orionis cache Config["config/cache.py"] --> Manager["CacheManager singleton"] Access["Cache or ICacheManager injection"] --> Manager Manager --> Repo["CacheRepository: applies the prefix"] Repo --> Backend["Selected driver"] Repo --> Locks["CacheLock"] Backend --> Values["Async reads and writes"]
The manager selects one of five native stores and retains its repository. The facade delegates to the same service resolved by the container. Value operations are asynchronous; the store() and lock() factories are synchronous. If your first facade operation selects a store, resolve cache = await Cache.resolve() first, then call cache.store("memory"). Its provider is deferred: importing Cache or booting the application does not guarantee resolution. Asynchronous calls such as await Cache.get(...) resolve it when awaited.
FileBasedCache is a separate synchronous API for artifacts derived from source files. It is not the file driver and does not use its TTL or prefix.
Continue with the guides
Section titled “Continue with the guides”- Drivers and dependencies: advantages, limits and external services for all five options.
- Configuration: every property, environment variable and default.
- Storing and regenerating values: complete repository API, TTL, batches and counters.
- Locks and concurrency: contexts, waiting and each backend’s guarantees.
- Source-derived artifacts: source invalidation and enriched serialization.
- Facade and injection: controllers, services and providers.
- Technical reference: contracts, backends, factories and errors.