\SimpleCache
A simple cache service that uses a configurable CacheStore for persisting items for a given length of time.
Usage
SimpleCache::get_cache('name')->get('mykey');
SimpleCache::get_cache('name')->store('mykey', {someobject}, 3600seconds);
Synopsis
class SimpleCache
{
- // constants
- const HIT_KEY = '__SC_HIT';
- const MISS_KEY = '__SC_MISS';
- // members
- private static array $default_caches = ;
- protected CacheStore $store = NULL;
- public static string $store_type = 'SimpleFileBasedCacheStore';
- public static Define $cache_configs = ;
- public integer $expiry = 0;
- private array $items = ;
- private static array $instances = ;
- private integer $hits = 0;
- private integer $misses = 0;
- public boolean $recordStats = false;
- // methods
- public CacheService inst()
- public static void register_caches()
- public static SimpleCache get_cache()
- public void __construct()
- public void configure()
- public void shutdown()
- public void stats()
- protected void tagKey()
- public void store()
- public void get()
- public array getByTag()
- public void getCacheEntry()
- public void delete()
- public void deleteByTag()
- public void expire()
- public void clear()
- public SimpleCacheStore getStore()
Constants
Name | Value |
---|---|
HIT_KEY | '__SC_HIT' |
MISS_KEY | '__SC_MISS' |
Members
private
- $default_caches
- $hits
—
int
Track hits and misses - $instances
—
array
Track cache instances - $items
—
array
In memory object store - $misses
protected
- $store
—
CacheStore
The cache store to use for actually putting and retrieving items from
public
- $cache_configs — Define
- $expiry — int
- $recordStats
- $store_type
—
string
The type of store we're using for the cache
Methods
protected
public
- __construct()
- clear() — Flush the whole cache clean
- configure() — Set config for this cache
- delete() — Delete from the cache
- deleteByTag() — Clear out all elements with a particular tag
- expire() — Explicitly expire the given key
- get() — Gets a cached value for a given key
- getByTag() — Get a list of items by tag
- getCacheEntry() — Gets the raw item underneath a given key, so we can see things about expiry etc
- getStore() — If underlying store access is needed; avoid using if possible!
- get_cache() — Get a named cache
- inst() — Get the instance
- register_caches() — Registers caches in the injector
- shutdown() — On shutdown, store hits and misses
- stats() — Gets statistics about this cache
- store() — Cache an item