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_TEXT
The identifier this cache object is for
append(\ID_TEXT $key, mixed $value, mixed $value_2 = true
) : boolean
This is efficient for duplication prevention.
\ID_TEXT
Cache key
mixed
Value to append (must not be an object or array, so you may need to pre-serialize)
mixed
Secondary value to attach to appended value (optional)
boolean
Whether the value was appended (false if it was already there)erase_smart_cache()
get(\ID_TEXT $key) : \?mixed
\ID_TEXT
Cache key
\?mixed
The value (null: not in cache - needs to be learnt)get_initial_status(\ID_TEXT $key) : boolean
\ID_TEXT
Cache key
boolean
Whether it wasinvalidate()
is_on() : boolean
boolean
Whether it isset(\ID_TEXT $key, mixed $value)
\ID_TEXT
Cache key
mixed
Value. Should not be null, as that is reserved for "not in cache"
load()
save(boolean $do_immediately = false
)
boolean
Immediately save the cache change (slow...)
$bucket_name
null
$data
null
$keys_inital
array()
$path
null
$pending_save
false