The PxActiveObjectCache Class
PxActiveObjectCache: The cache for instances that are currently in use.
This cache is used to make sure that no two instances are created for the same object (if license #13 is
requested twice, you can be sure that you will get the same object on the second request)
requested twice, you can be sure that you will get the same object on the second request)
Synopsis
Class PxActiveObjectCache extends PxWrappedCollection implements IteratorAggregate, Traversable, Countable, ArrayAccess, PxCollection
Properties
Inherited properties
Methods
public PxActiveObjectCache::__construct ( [integer $min = 20], [integer $max = 40], [boolean $removeOldestRetrieved = false] )
Inherited methods
Examples
Example
PxActiveObjectCache usage
// Create the cache
$cache = new PxActiveObjectCache();
// Create an object and store it in the cache
$x = new stdClass();
$cache->add('id', $x);
// Retrieve the same variable from the cache
$y = $cache->get('id');
// The object is kept in the cache as long as the cache size has not exceeded
// its limit, or as long as there are references to the variable in the script.
// At this moment, there are still two references the variables: $x and $y,
// so the variable will stay in the cache, even when the cache size has
// exceeded the size limit.
// remove references to the cached object
unset($x);
unset($y);
// The object is still stored in the cache, get the reference to it
$object = $cache->get('id');
// Remove the reference to the object
unset($object);
// The object is still in the cache, but because there are no other references
// to the object, it will automatically disappear from the cache when the
// cache grows too big. Let's put a lot of other objects in the cache
for ($i=0; $i<1000000; $i++) $cache->add(uniqid(), new stdClass());
// The size of the cache has now exceeded the max cache size. The original
// cached object that we had stored in the cache, should now be gone
if (!$cache->contains('id')) echo("Object no longer in cache...\n");
