Knowledge Base / The Appnel Group 

Last Modified
9 January 2007 @ 3pm

MT::Telegraph::CacheMgr

NAME

MT::Telegraph::CacheMgr - Telegraph framework manager for handling the local storage of data retrieved by agents.

VERSION

Telegraph 0.62

SYNOPSIS

  use MT::Telegraph::CacheMgr;

  my $p = {cache_root => '/path/to/cache/directory'};

  my $cache =
    MT::Telegraph::CacheMgr->new('File', $p)
      or die MT::Telegraph::CacheMgr->errstr;

DESCRIPTION

MT::Telegraph::CacheMgr is the telegraph framework manager for handling the local storage of data retrieved by agents. Caching is used in Telegraph to reduce bandwidth usage and speed processing of remote content.

The Telegraph Cache Manager uses derived classes that store cached data in different manners such as files on a filesystem, or in the Movable Type object store.

USAGE

The MT::CacheMgr interface is implemented by subclasses that store cached data in different manners (such as as files on a filesystem, or in memory).

MT::CacheMgr is used to instantiate a cache interface and as a base class for all cache manager drivers. This is a similar pattern to the one used by MT::FileMgr, Movable Type's built-in file management system.

The cache management functions and interface is a simplified version of the the Cache package found in CPAN.

METHODS

  • MT::CacheMgr->new($type,[\%param])

    Constructor for all cache manager types.

    Takes a required driver type and parameters HASH reference and return a cache manager object. The driver class that will be loaded, instantiated and returned is the type parameter with 'MT::Telegraph::CacheMgr::' prepended. For instance, calling new with a type of 'File' will instantiate a MT::Telegraph::CacheMgr::File object.

    While the cache manager base class does not require parameters per se, a cache driver may chose to do so. See the specific cache driver documentation for more details.

    NOTE: Subclasses should not overload this method, but use the init method instead.

  • $cache->init([\%param])

    This method contains any logic necessary to initialize a cache manager driver. The method in MT::CacheMgr does nothing, but return the cache object. Subclasses will typically overload this method to the logic specific to its purpose.

    The new method calls this method after loading the driver class and instantiates an object. The parameters HASH reference given to new is passed through. The init method is expected to return the cache object if successful or undef in coordination with the error method instead.

  • $cache->default_expires

    The current default expiration time in seconds since the epoch and the expiry defined by set_default_expires.

  • $cache->set_default_expires($expiry)

    Set the expiry time for all data in the cache based on the required expiry string parameter. The expiry string can be expressed in seconds since the epoch, or alternatively using a string like '10 minutes'. Valid units are s, second, seconds, sec, m, minute, minutes, min, h, hour, hours, w, week, weeks, M, month, months, y, year and years. You can also specify an absolute time, such as '16 Nov 94 22:28:20' or any other time that Date::Parse can understand. Finally, the strings 'now' and 'never' may also be used.

  • $cache->purge

    Remove all expired data from the cache.

  • $cache->clear

    Remove all entries from the cache regardless of their expiry time.

  • $cache->exists($key)

    Returns a boolean value to indicate whether there is any data present in the cache with the given key. Takes a required key parameter that identifies the specific data to check.

  • $cache->set($key,$data)

    Stores data into the cache with a specific key identifier. Takes a required key identifier and a required SCALAR (or SCALAR reference) containing the data to be cache. Serialization will be handled transparently by the specific cache driver in use.

    NOTE: If a key is already in use, the existing data will simply be overwritten. To avoid this always check a key with the exists method.

  • $cache->get($key)

    Returns the data from the cache, or undef if nothing exists. Takes a required key parameter that identifies the specific data to retrieve.

  • $cache->remove($key)

    Clear the data for this key from the cache.

    Takes a required key parameter that identifies the specific data to retrieve.

  • error

    Inherited from MT::ErrorHandler, sets an error message and return undef.

  • errstr

    Inherited from MT::ErrorHandler, returns the last error message for the class/object.

AUTHOR & COPYRIGHT

Copyright 2005-2007 Appnel Internet Solutions, LLC, info@appnel.com. All Rights Reserved. This code cannot be redistributed without permission of the author.


 

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated. Please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form.

Back to Home