The self-learning cache is an adaptive per-page/script cache, which loads from disk in a single efficient operation.
If something will not 'get' then the expectation is that a more costly "full load" or "upfront work" operation will be performed, but a 'set' will also happen so on next script load this won't be needed (at least, eventually, after things settle down across different access patterns).
The cache size is minimised, only required resources by the particular per-page/script are put there. Typically cache entries will be very small and voluminous, but predictable, hence why we don't just use individual fetches on a conventional cache layer. It is a disk vs CPU tradeoff. The intent is to approach performance as if each page/script were hand-coded to know its exact dependencies.
Some usage notes: Cached items should not be too volatile, although the cache is clever enough to not re-save if no real changes actually resulted from set/append operations; in other words the cache should quickly stabilise and not keep having to do writes You should not use this as an alternative to the persistent cache for caching everything that the persistent cache can already do; although sometimes it is good to do special batching operations (e.g. avoid repeating query patterns) that would already be separately optimised when the persistent cache was on We cannot always put cache stuff direct into smart cache as it may vary per-usergroup for example; anything in the cache really should be useful for all page loads, we do not want to have to load a great bloated smart cache on each page load; the above said, we will often say what is needed, then feed this in for doing bulk loads from the dedicated caches (e.g. saying which blocks to bulk load)
| package | core |
|---|
__construct(\ID_TEXT $bucket_name)
\ID_TEXTThe identifier this cache object is for
append(\ID_TEXT $key, mixed $value, mixed $value_2 = true) : boolean
This is efficient for duplication prevention.
\ID_TEXTCache key
mixedValue to append (must not be an object or array, so you may need to pre-serialize)
mixedSecondary value to attach to appended value (optional)
booleanWhether the value was appended (false if it was already there)erase_smart_cache()
get(\ID_TEXT $key) : \?mixed
\ID_TEXTCache key
\?mixedThe value (null: not in cache - needs to be learnt)get_initial_status(\ID_TEXT $key) : boolean
\ID_TEXTCache key
booleanWhether it wasinvalidate()
is_on() : boolean
booleanWhether it isset(\ID_TEXT $key, mixed $value)
\ID_TEXTCache key
mixedValue. Should not be null, as that is reserved for "not in cache"
load()
save(boolean $do_immediately = false)
booleanImmediately save the cache change (slow...)
$bucket_name
null$data
null$keys_inital
array()$path
null$pending_save
false