CacheFactory
What it is
- A small factory module that builds
CacheServiceinstances backed by:- a filesystem cache under a
storage/.../cachepath, or - an object storage backend via
ObjectStorageService.
- a filesystem cache under a
Public API
class CacheFactoryCacheFS_find_storage(subpath: str = "cache", needle: str = "storage") -> CacheService- Creates a
CacheServiceconfigured with a single cold-tier (TIER_COLD)CacheFSAdapter. - Locates (or creates) a
storagefolder relative to the current working directory, then appendssubpathunder acacheroot.
- Creates a
CacheObjectStorage(object_storage: ObjectStorageService, cache_prefix: str = "cache") -> CacheService- Creates a
CacheServiceconfigured with a single cold-tier (TIER_COLD)CacheObjectStorageAdapter. - Uses
cache_prefixas the key prefix in the object storage backend.
- Creates a
Configuration/Dependencies
- Depends on:
CacheServiceandTIER_COLDCacheFSAdapterCacheObjectStorageAdapterObjectStorageServicefind_storage_folderandNoStorageFolderFound
- Filesystem variant behavior:
- Uses
os.getcwd()as the starting point forfind_storage_folder(...). - If no storage folder is found, creates
./storageand retries.
- Uses
Usage
from naas_abi_core.services.cache.CacheFactory import CacheFactory
# Filesystem-backed cache (auto-finds or creates ./storage, then uses storage/.../cache)
cache = CacheFactory.CacheFS_find_storage()
# Optional subpath (will be placed under "cache/<subpath>" unless it already starts with "cache")
cache2 = CacheFactory.CacheFS_find_storage(subpath="my_app")
from naas_abi_core.services.cache.CacheFactory import CacheFactory
from naas_abi_core.services.object_storage.ObjectStorageService import ObjectStorageService
# Object storage-backed cache
object_storage = ObjectStorageService(...) # construct per your environment
cache = CacheFactory.CacheObjectStorage(object_storage, cache_prefix="cache")
Caveats
CacheFS_find_storagewill create astoragedirectory in the current working directory if no storage folder is found byfind_storage_folder(...).subpathis forced under acacheroot unless it already starts with"cache".