Fugitive Thought

Login | Register | RSS | Help

FTCache - PHP Generic Caching Library - Strategies

small logo

Overview

Strategies determine which entries to cache and which ones not to cache. They also determine what index within the cache the entry will be stored at. All strategies extend FTCache_Strategy. A strategy is instantiated with a size that is the size of the cache (maximum number of objects that it will hold). The constructor will throw an exception if the given size is invalid. The fromCache() method converts an index of an entry in the cache and tells us what object id is stored there right now (false if none or invalid). The toCache() method converts an object id to the cache index where it would be stored, or false if it would not be stored in the cache. The stored() method is used to notify the strategy algorithm that we are actually storing the given object in the cache so they it can adjust its functionality accordingly if needed.

Below are the strategies that are provided with the library.

Direct Mapping Strategy

The direct mapping strategy provides a static mapping between a given object id and the cache index it will be stored at (assuming a static cache size). The operation used is a modulus (%) operator, which means divide one number by the other and use the remainder. For example, if the cache is of size 5, then the strategy will take the object id and modulus it with 5. An object id of 4 will be stored at the cache index 4 % 5 = 4, and object id of 5 would be stored at 5 % 5 = 0. This means that at any given moment, the cache entry at index J will be filled with the most recently provided object whose id modulus 5 equals J.

About Us | Site Map | Privacy Policy | Contact Us | ©2006 Justin DeMaris & Steven Maresca