{
    "content": [
        {
            "type": "text",
            "text": "# Cache::Cache (perldoc)\n\n**Summary:** Cache::Cache -- the Cache interface.\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **DESCRIPTION** (26 lines)\n- **USAGE** (34 lines)\n- **CONSTANTS** (6 lines)\n- **METHODS** (56 lines)\n- **OPTIONS** (25 lines)\n- **PROPERTIES** (28 lines)\n- **SEE ALSO** (5 lines)\n- **AUTHOR** (6 lines)\n\n## Full Content\n\n### NAME\n\nCache::Cache -- the Cache interface.\n\n### DESCRIPTION\n\nThe Cache modules are designed to assist a developer in persisting data\nfor a specified period of time. Often these modules are used in web\napplications to store data locally to save repeated and redundant\nexpensive calls to remote machines or databases. People have also been\nknown to use Cache::Cache for its straightforward interface in sharing\ndata between runs of an application or invocations of a CGI-style script\nor simply as an easy to use abstraction of the filesystem or shared\nmemory.\n\nThe Cache::Cache interface is implemented by classes that support the\nget, set, remove, size, purge, and clear instance methods and their\ncorresponding static methods for persisting data across method calls.\n\nCACHE::CACHE VERSUS CHI\nCache::Cache is in wide use and very stable, but has not changed in\nyears and is no longer actively developed.\n\nCHI is the successor to Cache::Cache. It adheres to the basic\nCache::Cache API but adds new features and drivers (e.g. FastMmap and\nMemcached), improves performance, and addresses limitations in the\nCache::Cache implementation. The authors recommend the use of CHI going\nforward.\n\nQuestions about Cache::Cache and CHI may be directed to the perl-cache\nmailing list at http://groups.google.com/group/perl-cache-discuss.\n\n### USAGE\n\nFirst, choose the best type of cache implementation for your needs. The\nsimplest cache is the MemoryCache, which is suitable for applications\nthat are serving multiple sequential requests, and wish to avoid making\nredundant expensive queries, such as an Apache/modperl application\ntalking to a database. If you wish to share that data between processes,\nthen perhaps the SharedMemoryCache is appropriate, although its behavior\nis tightly bound to the underlying IPC mechanism, which varies from\nsystem to system, and is unsuitable for large objects or large numbers\nof objects. When the SharedMemoryCache is not acceptable, then FileCache\noffers all of the same functionality with similar performance metrics,\nand it is not limited in terms of the number of objects or their size.\nIf you wish to maintain a strict limit on the size of a file system\nbased cache, then the SizeAwareFileCache is the way to go. Similarly,\nthe SizeAwareMemoryCache and the SizeAwareSharedMemoryCache add size\nmanagement functionality to the MemoryCache and SharedMemoryCache\nclasses respectively.\n\nUsing a cache is simple. Here is some sample code for instantiating and\nusing a file system based cache.\n\nuse Cache::FileCache;\n\nmy $cache = new Cache::FileCache( );\n\nmy $customer = $cache->get( $name );\n\nif ( not defined $customer )\n{\n$customer = getcustomerfromdb( $name );\n$cache->set( $name, $customer, \"10 minutes\" );\n}\n\nreturn $customer;\n\n### CONSTANTS\n\n*$EXPIRESNEVER*\nThe item being set in the cache will never expire.\n\n*$EXPIRESNOW*\nThe item being set in the cache will expire immediately.\n\n### METHODS\n\nClear( )\nRemove all objects from all caches of this type.\n\nPurge( )\nRemove all objects that have expired from all caches of this type.\n\nSize( )\nReturns the total size of all objects in all caches of this type.\n\nnew( $optionshashref )\nConstruct a new instance of a Cache::Cache. *$optionshashref* is a\nreference to a hash containing configuration options; see the\nsection OPTIONS below.\n\nclear( )\nRemove all objects from the namespace associated with this cache\ninstance.\n\nget( $key )\nReturns the data associated with *$key*.\n\ngetobject( $key )\nReturns the underlying Cache::Object object used to store the cached\ndata associated with *$key*. This will not trigger a removal of the\ncached object even if the object has expired.\n\npurge( )\nRemove all objects that have expired from the namespace associated\nwith this cache instance.\n\nremove( $key )\nDelete the data associated with the *$key* from the cache.\n\nset( $key, $data, [$expiresin] )\nAssociates *$data* with *$key* in the cache. *$expiresin* indicates\nthe time in seconds until this data should be erased, or the\nconstant $EXPIRESNOW, or the constant $EXPIRESNEVER. Defaults to\n$EXPIRESNEVER. This variable can also be in the extended format of\n\"[number] [unit]\", e.g., \"10 minutes\". The valid units are s,\nsecond, seconds, sec, m, minute, minutes, min, h, hour, hours, d,\nday, days, w, week, weeks, M, month, months, y, year, and years.\nAdditionally, $EXPIRESNOW can be represented as \"now\" and\n$EXPIRESNEVER can be represented as \"never\".\n\nsetobject( $key, $object )\nAssociates *$key* with Cache::Object *$object*. Using setobject (as\nopposed to set) does not trigger an automatic removal of expired\nobjects.\n\nsize( )\nReturns the total size of all objects in the namespace associated\nwith this cache instance.\n\ngetnamespaces( )\nReturns all the namespaces associated with this type of cache.\n\n### OPTIONS\n\nThe options are set by passing in a reference to a hash containing any\nof the following keys:\n\n*namespace*\nThe namespace associated with this cache. Defaults to \"Default\" if\nnot explicitly set.\n\n*defaultexpiresin*\nThe default expiration time for objects place in the cache. Defaults\nto $EXPIRESNEVER if not explicitly set.\n\n*autopurgeinterval*\nSets the auto purge interval. If this option is set to a particular\ntime ( in the same format as the expiresin ), then the purge( )\nroutine will be called during the first set after the interval\nexpires. The interval will then be reset.\n\n*autopurgeonset*\nIf this option is true, then the auto purge interval routine will be\nchecked on every set.\n\n*autopurgeonget*\nIf this option is true, then the auto purge interval routine will be\nchecked on every get.\n\n### PROPERTIES\n\n(get|set)namespace( )\nThe namespace of this cache instance\n\ngetdefaultexpiresin( )\nThe default expiration time for objects placed in this cache\ninstance\n\ngetkeys( )\nThe list of keys specifying objects in the namespace associated with\nthis cache instance\n\ngetidentifiers( )\nThis method has been deprecated in favor of getkeys( ).\n\n(get|set)autopurgeinterval( )\nAccesses the auto purge interval. If this option is set to a\nparticular time ( in the same format as the expiresin ), then the\npurge( ) routine will be called during the first get after the\ninterval expires. The interval will then be reset.\n\n(get|set)autopurgeonset( )\nIf this property is true, then the auto purge interval routine will\nbe checked on every set.\n\n(get|set)autopurgeonget( )\nIf this property is true, then the auto purge interval routine will\nbe checked on every get.\n\n### SEE ALSO\n\nCHI - the successor to Cache::Cache\n\nCache::Object, Cache::MemoryCache, Cache::FileCache,\nCache::SharedMemoryCache, and Cache::SizeAwareFileCache\n\n### AUTHOR\n\nOriginal author: DeWitt Clinton <dewitt@unto.net>\n\nLast author: $Author: dclinton $\n\nCopyright (C) 2001-2003 DeWitt Clinton\n\n"
        }
    ],
    "structuredContent": {
        "command": "Cache::Cache",
        "section": "",
        "mode": "perldoc",
        "summary": "Cache::Cache -- the Cache interface.",
        "synopsis": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "USAGE",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "CONSTANTS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 56,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "PROPERTIES",
                "lines": 28,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 6,
                "subsections": []
            }
        ]
    }
}