abstract class vB_Cache

Cache Handler that caches and retrieves data.

Traits

Constants

CACHE_STD

CACHE_FAST

CACHE_LARGE

CACHE_LOG_WRITE

CACHE_LOG_READSUCCESS

CACHE_LOG_READFAIL

CACHE_LOG_HASVALUE

CACHE_LOG_NOVALUE

CACHE_LOG_CLEAR

Properties

static protected vB_Cache $instance A reference to the singleton instance
protected $values_read
protected $no_values
protected $metadata_life
protected $metadata_update_min
protected $meta_info
protected $keys_used
protected $noCache
static protected $disableCache
protected string $prefix Unique prefix for item's title, required for multiple forums on the same server using the same classes that read/write to memory
protected string $cachetype Cache type of current object.
protected $timeNow The current time - this is used a lot so let's make it a member variable.
protected $meta_loaded
static protected $cacheLogging
static protected $actions

Methods

__sleep()

No description

__wakeup()

No description

__construct($cachetype)

Constructor protected to enforce singleton use.

static 
getDefaults()

Get the cache defaults.

static vB_Cache
instance($type = self::CACHE_STD)

Returns an instance of the global cache.

static 
resetCache($expiredOnly = false)

No description

static 
resetAllCache($expiredOnly = false)

No description

string
write($key, $data, $lifetime_mins = false, $events = false)

Writes data as a cache object.

writeCache(array $cache)

Writes the cache data to storage.

saveCacheInfo($cacheid)

Based on the assumption that if we go back to a page we're likely to request a lot of the information we requested last time we were on that page, let's store the cached information.

restoreCacheInfo($cacheid)

If we used saveCacheInfo to save data, this will get it back.

bool
isLoaded(string $key)

has a value been loaded for this key?

mixed
readSingle($key, $write_lock = false, $save_meta = false)

Reads a cache object and returns the data.

array
readCache(string $key)

Reads the cache object from storage.

purge($cacheid)

Purges a cache object.

purgeCache(int $cache_id)

Removes a cache object from storage.

expire(int/array $cache_ids)

Expires a cache object.

bool
expireCache(int $cache_id)

Sets a cache entry as expired in storage.

event(string $events)

Expires cache objects based on a triggered event.

static 
allCacheEvent($events)

No description

bool
lock(mixed $keys)

Locks a cache entry.

unlock(mixed $keys)

Unlocks a cache entry.

clean(bool $only_expired = true)

Cleans cache.

shutdown()

No description

cleanNow()

Tells the cache to trigger all events.

array
read(string $keys, bool $writeLock = false, bool $save_meta = false)

Reads an array of cache objects from storage.

updateTime($time = false)

This updates the time. It is useful only for testing. Otherwise it does nothing

static 
logCacheAction($cacheid, $action, $type = 4, $size = 0)

If cache logging is enabled this stores the page cache activity to be loggged.

logCacheActivity()

If cache logging is enabled this function writes the activity for this page to the database.

getSize($data)

No description

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

at line 135
protected __construct($cachetype)

Constructor protected to enforce singleton use.

Parameters

$cachetype

See also

instance()

at line 176
static getDefaults()

Get the cache defaults.

at line 191
static vB_Cache instance($type = self::CACHE_STD)

Returns an instance of the global cache.

The cache type used is defined in options.

Parameters

$type

Return Value

vB_Cache
  • Reference to instance of the cache handler

at line 237
static resetCache($expiredOnly = false)

Parameters

$expiredOnly

at line 252
static resetAllCache($expiredOnly = false)

Parameters

$expiredOnly

at line 287
string write($key, $data, $lifetime_mins = false, $events = false)

Writes data as a cache object.

A string key is required to uniquely identify a cache object. Client code should add all information that would affect the individualisation of the cache object to the key.

If lifetime_mins is supplied the cache object will be purged the next time it is read after the TTL has passed.

If a cache object should be purged on triggered events then events should be supplied as an array of string id's of the form 'scope.event', for example 'widget55.updated' may be used to purge a cache of a defined widget with the id 55 when it is reconfigured.

Parameters

$key
$data
$lifetime_mins
$events

Return Value

string | bool - Cache id or false

at line 338
abstract protected writeCache(array $cache)

Writes the cache data to storage.

Parameters

array $cache includes key, data, expires

at line 346
saveCacheInfo($cacheid)

Based on the assumption that if we go back to a page we're likely to request a lot of the information we requested last time we were on that page, let's store the cached information.

Parameters

$cacheid

at line 406
restoreCacheInfo($cacheid)

If we used saveCacheInfo to save data, this will get it back.

**

Parameters

$cacheid

at line 433
bool isLoaded(string $key)

has a value been loaded for this key?

Parameters

string $key the key

Return Value

bool

at line 464
mixed readSingle($key, $write_lock = false, $save_meta = false)

Reads a cache object and returns the data.

Integrity checking should be performed by the client code, ensuring that the returned data is in the expected form.

$key should be a string key with all of the identifying information for the required cache objects. This must match the $key used to write the cache object.

The implicit lock can be set to true to indicate that the client code will rebuild the cache on an expired read. This allows cache handlers to lock the cache for the current connection. Normally, if a cache entry is locked then subsequent reads should return the expired cache data until it is unlocked. This cannot be done for cache entries that don't yet exist, but can be used on existing entries to prevent cache slams - where multiple connections decide to rebuild the cache under a race condition.

Cache handlers should ensure to implement an expiration on cache locks.

Parameters

$key
$write_lock
$save_meta

Return Value

mixed
  • The cached data (string or array of strings) or boolean false

See also

cache::Write()

at line 517
abstract protected array readCache(string $key)

Reads the cache object from storage.

Parameters

string $key
  • Identifying key

Return Value

array includes key, data, expires

at line 524
purge($cacheid)

Purges a cache object.

Parameters

$cacheid

at line 541
abstract protected purgeCache(int $cache_id)

Removes a cache object from storage.

Parameters

int $cache_id
  • Id of the cache entry to purge

at line 551
expire(int/array $cache_ids)

Expires a cache object.

This is preferred to purging a cache entry as it ensures that that the cache data can still be served while new cache data is being rebuilt.

Parameters

int/array $cache_ids
  • Id of the cache entry to expire

at line 581
abstract protected bool expireCache(int $cache_id)

Sets a cache entry as expired in storage.

Parameters

int $cache_id
  • Id of the cache entry to expire

Return Value

bool

at line 588
abstract event(string $events)

Expires cache objects based on a triggered event.

Parameters

string $events | array $event - The name of the event

at line 590
static allCacheEvent($events)

Parameters

$events

at line 610
bool lock(mixed $keys)

Locks a cache entry.

This is done to prevent a cache slam where concurrent connections attempt to rebuild an expired cache entry. While a cache entry is locked, it should be considered valid and served to all connections except the one that has the lock. After the cache entry has been rebuilt it will be unlocked, allowing all new connections to consume the fresh entry.

Parameters

mixed $keys array of string $key - Identifying key

Return Value

bool
  • TRUE iff the lock was obtained

at line 620
unlock(mixed $keys)

Unlocks a cache entry.

Most implementations may unlock the cache during write, making this redundant.

Parameters

mixed $keys array of string $key - Identifying key

at line 633
abstract clean(bool $only_expired = true)

Cleans cache.

$created_before should be a unix timestamp.

Parameters

bool $only_expired
  • Only clean expired entries

at line 640
shutdown()

at line 651
cleanNow()

Tells the cache to trigger all events.

at line 670
array read(string $keys, bool $writeLock = false, bool $save_meta = false)

Reads an array of cache objects from storage.

Parameters

string $keys
  • Ids of the cache entry to read
bool $writeLock whether to lock the values
bool $save_meta whether to save this cache id and preload the value for the page next time.

Return Value

array of array includes key, data, expires

at line 795
updateTime($time = false)

This updates the time. It is useful only for testing. Otherwise it does nothing

@param integer timestamp- optional

Parameters

$time

at line 811
static protected logCacheAction($cacheid, $action, $type = 4, $size = 0)

If cache logging is enabled this stores the page cache activity to be loggged.

Parameters

$cacheid
$action
$type
$size

at line 870
protected logCacheActivity()

If cache logging is enabled this function writes the activity for this page to the database.

at line 908
protected getSize($data)

Parameters

$data