Cache
APPNETOS Core infrastructure component: Cache.
Core\Cache manages cache documents and invalidation across the APPNETOS runtime. It is not
synonymous with Redis: most cache metadata is loaded from MongoDB into PHP memory and changed records are
persisted during shutdown, while the database-document cache uses Redis.
Supported and planned cache types
| Constant | Type | Intended behavior |
|---|---|---|
TYPE_FILE |
File | Cache resolved class and template file paths, including custom overrides, to avoid repeated searches. |
TYPE_DIRECTORY |
Directory | Cache registered autoload directories so directory discovery need not be repeated. |
TYPE_TRANSLATION |
Translation | Collect and cache discovered translations by language. |
TYPE_JS |
JavaScript | Generate public JavaScript assets from app scripts; include them in the document head. Unique hashed filenames prevent stale browser assets after cache renewal. |
TYPE_CSS |
CSS | Generate and publish CSS assets with cache-busting hashed filenames, analogous to JavaScript. |
TYPE_DATABASE |
Database | Cache database documents in Redis; disabled when Redis is unavailable. |
TYPE_APP |
App | Cache the fully rendered, language-specific app output; cache hits skip class execution, translation gathering and rendering. |
TYPE_CONTENT |
Content | Cache prepared, language-specific content results permanently without TTL; invalidation occurs when content changes. |
TYPE_CONTENT_ELEMENT |
Content element | Equivalent persistent result caching for future content elements. |
TYPE_REST |
REST | Cache functions found by REST discovery to avoid rediscovery on subsequent requests. |
Scope and fallback
Cache entries are scoped by application, base context, optional language, type and optional type ID. The
runtime key is application:context:language:type:typeId. On reads, the current application
is
checked first; if absent, the shared APPNETOS cache entry is used as a fallback.
Cache invalidation and generated files
The controller can delete a single entry, a type, an application/context scope, or the complete cache.
JS/CSS
invalidation also removes referenced generated public files. Complete cleanup recursively clears the
contents of public/appnetos/cache. A configured GET parameter can trigger a clear
operation.
Implementation status
The shared base provides cache document management, MongoDB persistence, scope handling, and cleanup. Specialized context controllers enable cache types. Not all ten cache producers/consumers are complete yet; the table describes the agreed target behavior.
Future application adapter
A future adapter will allow applications to cache arbitrary data independently of TYPE_APP,
which specifically caches fully rendered app output. Adapter interfaces and backends are not yet
finalized.
Public API Reference
Core\Cache
Class & Registry
Class:
Core\Cache
Extends:
Core\Cache\Base
use Core\Cache;
use Core\Registry;
$cache = Registry::get(Cache::class);
| Method | Description |
|---|---|
init() |
Initialize cache controller and load scoped documents. |
isEnabled() |
Check whether a cache type is enabled. |
get / has() |
Read cached data and check presence. |
set / delete() |
Update or delete an individual cache entry. |
clear() |
Clear one cache type for a scope. |
clearAll() |
Clear current application and base context. |
clearAppnetos() |
Clear shared APPNETOS cache for the current base context. |
clearScope() |
Clear selected applications, languages and optional type. |
clearByApplicationAndContext() |
Clear a specified application/context. |
clearCompleteCache() |
Clear all cache documents and generated cache directories. |
save / close() |
Persist pending changes, including on shutdown. |
getClearAllCachesParameter() |
Expose optional request parameter for cache clearing. |