PHP Class Elgg\Cache\MetadataCache

Show file Open project: elgg/elgg Class Usage Examples

Protected Properties

Property Type Description
$session ElggSession
$values array The cached values (or null for known to be empty).

Public Methods

Method Description
__construct ( ElggSession $session ) Constructor
clear ( integer $entity_guid ) : void Forget about all metadata for an entity. For safety this affects all access states.
clearAll ( ) : void Clear entire cache
filterMetadataHeavyEntities ( array $guids, integer $limit = 1024000 ) : array Filter out entities whose concatenated metadata values (INTs casted as string) exceed a threshold in characters. This could be used to avoid overpopulating the cache if RAM usage becomes an issue.
getSingle ( integer $entity_guid, string $name ) : array | string | integer | null Get the metadata for a particular name. Note, this can return an array of values.
inject ( integer $entity_guid, array $values ) : void Set the visible metadata for an entity in the cache
invalidateByOptions ( array $options ) : void Invalidate based on options passed to the global *_metadata functions
isLoaded ( integer $entity_guid ) : boolean If true, getSingle() will return an accurate values from the DB
populateFromEntities ( integer | array $guids ) : void Populate the cache from a set of entities

Protected Methods

Method Description
getAccessKey ( ) : string Get a key to represent the access ability of the system. This is used to shard the cache array.

Method Details

__construct() public method

Constructor
public __construct ( ElggSession $session )
$session ElggSession The session service

clear() public method

Forget about all metadata for an entity. For safety this affects all access states.
public clear ( integer $entity_guid ) : void
$entity_guid integer The GUID of the entity
return void

clearAll() public method

Clear entire cache
public clearAll ( ) : void
return void

filterMetadataHeavyEntities() public method

Filter out entities whose concatenated metadata values (INTs casted as string) exceed a threshold in characters. This could be used to avoid overpopulating the cache if RAM usage becomes an issue.
public filterMetadataHeavyEntities ( array $guids, integer $limit = 1024000 ) : array
$guids array GUIDs of entities to examine
$limit integer Limit in characters of all metadata (with ints casted to strings)
return array

getAccessKey() protected method

Get a key to represent the access ability of the system. This is used to shard the cache array.
protected getAccessKey ( ) : string
return string E.g. "ignored" or "123"

getSingle() public method

Warning: You should always call isLoaded() beforehand to verify that this function's return value can be trusted.
See also: isLoaded
public getSingle ( integer $entity_guid, string $name ) : array | string | integer | null
$entity_guid integer The GUID of the entity
$name string The metadata name
return array | string | integer | null null = value does not exist

inject() public method

Note this does NOT invalidate any other part of the cache.
public inject ( integer $entity_guid, array $values ) : void
$entity_guid integer The GUID of the entity
$values array The metadata values to cache
return void

invalidateByOptions() public method

Invalidate based on options passed to the global *_metadata functions
public invalidateByOptions ( array $options ) : void
$options array Options passed to elgg_(delete|disable|enable)_metadata "guid" if given, invalidation will be limited to this entity
return void

isLoaded() public method

If true, getSingle() will return an accurate values from the DB
public isLoaded ( integer $entity_guid ) : boolean
$entity_guid integer The GUID of the entity
return boolean

populateFromEntities() public method

Populate the cache from a set of entities
public populateFromEntities ( integer | array $guids ) : void
$guids integer | array Array of or single GUIDs
return void

Property Details

$session protected property

protected ElggSession $session
return ElggSession

$values protected property

The cached values (or null for known to be empty).
protected array $values
return array