Abstract Class Cache_ItemBase

Description

Cache_ItemBase is an abstract class for implementing the key object that must be returned by implementors of the Cache_Engine interface. It provides methods for working with the value associated with its key.

It's worth mentioning the lock and unlock methods of this class. Both methods must be implemented, but they do not need to do anything if the associated engine does not support key-level locking. That is to say, derived classes do not need to override these methods if they do not implement locking. Similarly mtime() does not need to be overridden if it is not appropriate. See that method's documentation for more details.

  • abstract:

Located in /cache/lib/Cache/ItemBase.php (line 20)


	
			
Direct descendents
Class Description
 class Cache_Engine_Apc_Item The key object for the apc cache engine.
 class Cache_Engine_File_Item The key object for the file cache engine.
 class Cache_Engine_Memcache_Item The key object for the memcache cache engine.
 class Cache_Engine_Memory_Item The key object for the memory cache engine.
Class Constant Summary
 LOCK_READ = LOCK_SH
 LOCK_WRITE = LOCK_EX
Variable Summary
 mixed $key
Method Summary
 Cache_ItemBase __construct (string $key)
 boolean exists ()
 string key ()
 void lock (int $type, [boolean $create = false])
 string marshall (mixed $value)
 int mtime ()
 mixed read ()
 void remove ()
 void unlock ()
 string unmarshall (mixed $value)
 void write (mixed $data)
Variables
mixed $key (line 21)
  • access: protected
Methods
Constructor __construct (line 33)

Constructor

  • access: public
Cache_ItemBase __construct (string $key)
  • string $key: The item's key

Redefined in descendants as:
exists (line 82)

Test for the existence of the key in the cache. Return true if it exists, false otherwise.

  • abstract:
  • access: public
boolean exists ()

Redefined in descendants as:
key (line 42)

Returns this item's key

  • access: public
string key ()
lock (line 66)

Acquire a lock on the key. The method is expected to block until the lock is acquired.

As mentioned in the documentation for the class, this method does not need to acquire a lock if the engine does not support it. In that case it should simply return (this is the default implementation).

For engines that implement locking, the create flag may affect the behavior of this method. When the create flag is false, it indicates that the key will not be created if it does not already exist (as in the case of testing for the existence of a key). In this case, it is permissible to not actually lock the key if it does not exist (for example, if in order to lock the key it must first be created). If the create flag is true, engines supporting locking must lock the key and should create the key at this time if needed.

  • access: public
void lock (int $type, [boolean $create = false])
  • int $type: The lock type, either LOCK_READ or LOCK_WRITE
  • boolean $create: The flag indicating whether to create the key or not (see above)

Redefined in descendants as:
marshall (line 127)

Given any value, returns a string representation of that value, serializing the value if necessary. This is convenient for preparing a value for storage for some engines.

  • access: protected
string marshall (mixed $value)
  • mixed $value: The data to marshall
mtime (line 93)

Return the last modified time (as a Unix timestamp) of the value

associated with the key. This is used for testing TTL expiration when the underlying engine does not handle it automatically. If the underlying engine handles TTL itself, simply return false. The default implementation always returns false.

  • access: public
int mtime ()

Redefined in descendants as:
read (line 105)

Return the value associated with the key from the cache

If the key does not have a value, this function must return null and it must not produce an exception.

  • abstract:
  • access: public
mixed read ()

Redefined in descendants as:
remove (line 117)

Remove the key from the cache

  • abstract:
  • access: public
void remove ()

Redefined in descendants as:
unlock (line 73)

Release any acquired lock for the key. As with lock(), this function should merely return (the default) if locking is not supported.

  • access: public
void unlock ()

Redefined in descendants as:
unmarshall (line 142)

This is the inverse of marshall(). Given a string value returned by marshall, returns the original value.

  • access: protected
string unmarshall (mixed $value)
  • mixed $value: The data to marshall
write (line 112)

Set the value associated with the key

  • abstract:
  • access: public
void write (mixed $data)
  • mixed $data: The value to associate with the key

Redefined in descendants as:
Class Constants
LOCK_READ = LOCK_SH (line 24)

A read, or shared lock type

LOCK_WRITE = LOCK_EX (line 26)

A write, or exclusive lock type

Documentation generated on Wed, 25 Apr 2012 09:46:43 -0700 by phpDocumentor 1.4.3