Zeta Components Manual :: Docs For Class ezcCacheStackLfuReplacementStrategy
Cache::ezcCacheStackLfuReplacementStrategy
Class ezcCacheStackLfuReplacementStrategy
Least frequently used replacement strategy.
This replacement strategy will purge items first that have been used least frequently. In case the ezcCacheStackableStorage this replacement strategy works on runs full, first all outdated items (which are older than TTL) will be purged. If this does not last to achieve the desired free rate, items will be purged that have been stored or restored least often.
This class is not intended to be used directly, but should be configured to be used by an ezcCacheStack instance. This can be achieved via ezcCacheStackOptions. The meta data class used by this class is ezcCacheStackLfuMetaData.
For more information on LFU see {@see http://en.wikipedia.org/wiki/Cache_algorithms}.
Source for this file: /Cache/src/replacement_strategies/lfu.php
ezcCacheStackBaseReplacementStrategy | --ezcCacheStackLfuReplacementStrategy
Version: | //autogentag// |
Method Summary
protected static void |
checkMetaData(
$metaData
)
Checks if the given meta data is processable. |
public static ezcCacheStackLfuMetaData |
createMetaData(
)
Returns a fresh meta data instance. |
public static array(string) |
delete(
$conf
, $metaData
, $itemId
, [ $itemAttributes
= array()] , [ $search
= false] )
Deletes the data with the given $itemId from the given $storage. |
public static mixed |
restore(
$conf
, $metaData
, $itemId
, [ $itemAttributes
= array()] , [ $search
= false] )
Restores the data with the given $itemId from the storage configured in $conf. |
public static void |
store(
$conf
, $metaData
, $itemId
, $itemData
, [ $itemAttributes
= array()] )
Stores the given $itemData in the given storage. |
Methods
checkMetaData
Checks if the given meta data is processable.
Throws an exception if the given meta data is not processable.
Parameters:
Name | Type | Description |
---|---|---|
$metaData |
ezcCacheStackMetaData |
Exceptions:
Type | Description |
---|---|
ezcCacheInvalidMetaDataException |
if the given $metaData is not an instance of ezcCacheStackLfuMetaData. |
createMetaData
Returns a fresh meta data instance.
Returns a freshly created instance of ezcCacheStackLfuMetaData.
delete
Deletes the data with the given $itemId from the given $storage.
Deletes the desired item with $itemId and optionally $itemAttributes from the ezcCacheStackableStorage configured in $conf using. The item IDs returned by this call are updated in $metaData, that they are no longer stored in the $storage.
Parameters:
Name | Type | Description |
---|---|---|
$conf |
ezcCacheStackStorageConfiguration | |
$metaData |
ezcCacheStackMetaData | |
$itemId |
string | |
$itemAttributes |
array(string=>string) | |
$search |
bool |
Exceptions:
Type | Description |
---|---|
ezcCacheInvalidMetaDataException |
if the given $metaData is not an instance of ezcCacheStackLfuMetaData. |
restore
Restores the data with the given $itemId from the storage configured in $conf.
This method restores the item data identified by $itemId and optionally $itemAttributes from the ezcCacheStackableStorage given in $conf using ezcCacheStackableStorage::restore(). The result of this action is returned by the method. This means, the desired item data is returned on success, false is returned if the data is not available.
A successful restore is recorded in $metaData as a "recent usage", with incrementing the usage counter of $itemId by 1. A restore failure results in a removal of $itemId.
Parameters:
Name | Type | Description |
---|---|---|
$conf |
ezcCacheStackStorageConfiguration | |
$metaData |
ezcCacheStackMetaData | |
$itemId |
string | |
$itemAttributes |
array(string=>string) | |
$search |
bool |
Exceptions:
Type | Description |
---|---|
ezcCacheInvalidMetaDataException |
if the given $metaData is not an instance of ezcCacheStackLfuMetaData. |
store
Stores the given $itemData in the given storage.
This method stores the given $itemData under the given $itemId and assigns the given $itemAttributes to it in the ezcCacheStackableStorage configured in $conf. The storing results in an update of $metaData, reflecting that the item with $itemId was used by raising its use frequence.
In case the number of items in the storage exceeds $conf->itemLimit, items will be deleted from the storage. First all outdated items will be removed using ezcCacheStackableStorage::purge(). If this does not free the desired $conf->freeRate fraction of $conf->itemLimit, those items that have been used least frequently will be deleted. The changes of freeing items are recorded in $metaData.
Parameters:
Name | Type | Description |
---|---|---|
$conf |
ezcCacheStackStorageConfiguration | |
$metaData |
ezcCacheStackMetaData | |
$itemId |
string | |
$itemData |
mixed | |
$itemAttributes |
array(string=>string) |
Exceptions:
Type | Description |
---|---|
ezcCacheInvalidMetaDataException |
if the given $metaData is not an instance of ezcCacheStackLfuMetaData. |