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

 Methods

Constructor. Initialise our cache.

__construct(\ID_TEXT $bucket_name) 

Parameters

$bucket_name

\ID_TEXT

The identifier this cache object is for

Add something to a list entry in the cache. Uses keys to set the value, then assigns $value_2 to the key.

append(\ID_TEXT $key, mixed $value, mixed $value_2 = true) : boolean

This is efficient for duplication prevention.

Parameters

$key

\ID_TEXT

Cache key

$value

mixed

Value to append (must not be an object or array, so you may need to pre-serialize)

$value_2

mixed

Secondary value to attach to appended value (optional)

Returns

booleanWhether the value was appended (false if it was already there)

Called by various other erase_* functions that know the smart cache may be involved.

erase_smart_cache() 
Static

Get a cache key.

get(\ID_TEXT $key) : \?mixed

Parameters

$key

\ID_TEXT

Cache key

Returns

\?mixedThe value (null: not in cache - needs to be learnt)

See if a cache key was initially set.

get_initial_status(\ID_TEXT $key) : boolean

Parameters

$key

\ID_TEXT

Cache key

Returns

booleanWhether it was

Invalidate the cache, so that it will rebuild.

invalidate() 

Find whether the smart cache is on.

is_on() : boolean
Static

Returns

booleanWhether it is

Set a cache key.

set(\ID_TEXT $key, mixed $value) 

Parameters

$key

\ID_TEXT

Cache key

$value

mixed

Value. Should not be null, as that is reserved for "not in cache"

Load the cache for the particular bucket this cache object is for.

load() 

Save the cache, after some change has happened.

save(boolean $do_immediately = false

Parameters

$do_immediately

boolean

Immediately save the cache change (slow...)

 Properties

 

$bucket_name

$bucket_name 

Default

null
 

$data

$data 

Default

null
 

$keys_inital

$keys_inital 

Default

array()
 

$path

$path 

Default

null
 

$pending_save

$pending_save 

Default

false