{
    "content": [
        {
            "type": "text",
            "text": "# Cache::Cache (perldoc)\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 for a specified period\nof time. Often these modules are used in web applications to store data locally to save repeated\nand redundant expensive calls to remote machines or databases. People have also been known to\nuse Cache::Cache for its straightforward interface in sharing data between runs of an\napplication or invocations of a CGI-style script or simply as an easy to use abstraction of the\nfilesystem or shared memory.\n\n## Sections\n\n- **NAME**\n- **DESCRIPTION**\n- **USAGE**\n- **CONSTANTS**\n- **METHODS** (10 subsections)\n- **OPTIONS**\n- **PROPERTIES** (3 subsections)\n- **SEE ALSO**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Cache::Cache",
        "section": "",
        "mode": "perldoc",
        "summary": "Cache::Cache -- the Cache interface.",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "USAGE",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "CONSTANTS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 9,
                "subsections": [
                    {
                        "name": "new",
                        "lines": 3
                    },
                    {
                        "name": "clear",
                        "lines": 2
                    },
                    {
                        "name": "get",
                        "lines": 2
                    },
                    {
                        "name": "get_object",
                        "lines": 3
                    },
                    {
                        "name": "purge",
                        "lines": 2
                    },
                    {
                        "name": "remove",
                        "lines": 2
                    },
                    {
                        "name": "set",
                        "lines": 8
                    },
                    {
                        "name": "set_object",
                        "lines": 3
                    },
                    {
                        "name": "size",
                        "lines": 2
                    },
                    {
                        "name": "get_namespaces",
                        "lines": 2
                    }
                ]
            },
            {
                "name": "OPTIONS",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "PROPERTIES",
                "lines": 3,
                "subsections": [
                    {
                        "name": "get_default_expires_in",
                        "lines": 2
                    },
                    {
                        "name": "get_keys",
                        "lines": 2
                    },
                    {
                        "name": "get_identifiers",
                        "lines": 13
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Cache::Cache -- the Cache interface.\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The Cache modules are designed to assist a developer in persisting data for a specified period\nof time. Often these modules are used in web applications to store data locally to save repeated\nand redundant expensive calls to remote machines or databases. People have also been known to\nuse Cache::Cache for its straightforward interface in sharing data between runs of an\napplication or invocations of a CGI-style script or simply as an easy to use abstraction of the\nfilesystem or shared memory.\n\nThe Cache::Cache interface is implemented by classes that support the get, set, remove, size,\npurge, and clear instance methods and their corresponding static methods for persisting data\nacross method calls.\n\nCACHE::CACHE VERSUS CHI\nCache::Cache is in wide use and very stable, but has not changed in years and is no longer\nactively developed.\n\nCHI is the successor to Cache::Cache. It adheres to the basic Cache::Cache API but adds new\nfeatures and drivers (e.g. FastMmap and Memcached), improves performance, and addresses\nlimitations in the Cache::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 mailing list at\nhttp://groups.google.com/group/perl-cache-discuss.\n",
                "subsections": []
            },
            "USAGE": {
                "content": "First, choose the best type of cache implementation for your needs. The simplest cache is the\nMemoryCache, which is suitable for applications that are serving multiple sequential requests,\nand wish to avoid making redundant expensive queries, such as an Apache/modperl application\ntalking to a database. If you wish to share that data between processes, then perhaps the\nSharedMemoryCache is appropriate, although its behavior is tightly bound to the underlying IPC\nmechanism, which varies from system to system, and is unsuitable for large objects or large\nnumbers of objects. When the SharedMemoryCache is not acceptable, then FileCache offers all of\nthe same functionality with similar performance metrics, and it is not limited in terms of the\nnumber of objects or their size. If you wish to maintain a strict limit on the size of a file\nsystem based cache, then the SizeAwareFileCache is the way to go. Similarly, the\nSizeAwareMemoryCache and the SizeAwareSharedMemoryCache add size management functionality to the\nMemoryCache and SharedMemoryCache classes respectively.\n\nUsing a cache is simple. Here is some sample code for instantiating and using a file system\nbased 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",
                "subsections": []
            },
            "CONSTANTS": {
                "content": "*$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",
                "subsections": []
            },
            "METHODS": {
                "content": "Clear( )\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",
                "subsections": [
                    {
                        "name": "new",
                        "content": "Construct a new instance of a Cache::Cache. *$optionshashref* is a reference to a hash\ncontaining configuration options; see the section OPTIONS below.\n"
                    },
                    {
                        "name": "clear",
                        "content": "Remove all objects from the namespace associated with this cache instance.\n"
                    },
                    {
                        "name": "get",
                        "content": "Returns the data associated with *$key*.\n"
                    },
                    {
                        "name": "get_object",
                        "content": "Returns the underlying Cache::Object object used to store the cached data associated with\n*$key*. This will not trigger a removal of the cached object even if the object has expired.\n"
                    },
                    {
                        "name": "purge",
                        "content": "Remove all objects that have expired from the namespace associated with this cache instance.\n"
                    },
                    {
                        "name": "remove",
                        "content": "Delete the data associated with the *$key* from the cache.\n"
                    },
                    {
                        "name": "set",
                        "content": "Associates *$data* with *$key* in the cache. *$expiresin* indicates the time in seconds\nuntil this data should be erased, or the constant $EXPIRESNOW, or the constant\n$EXPIRESNEVER. Defaults to $EXPIRESNEVER. This variable can also be in the extended format\nof \"[number] [unit]\", e.g., \"10 minutes\". The valid units are s, second, seconds, sec, m,\nminute, minutes, min, h, hour, hours, d, day, days, w, week, weeks, M, month, months, y,\nyear, and years. Additionally, $EXPIRESNOW can be represented as \"now\" and $EXPIRESNEVER\ncan be represented as \"never\".\n"
                    },
                    {
                        "name": "set_object",
                        "content": "Associates *$key* with Cache::Object *$object*. Using setobject (as opposed to set) does\nnot trigger an automatic removal of expired objects.\n"
                    },
                    {
                        "name": "size",
                        "content": "Returns the total size of all objects in the namespace associated with this cache instance.\n"
                    },
                    {
                        "name": "get_namespaces",
                        "content": "Returns all the namespaces associated with this type of cache.\n"
                    }
                ]
            },
            "OPTIONS": {
                "content": "The options are set by passing in a reference to a hash containing any of the following keys:\n\n*namespace*\nThe namespace associated with this cache. Defaults to \"Default\" if not explicitly set.\n\n*defaultexpiresin*\nThe default expiration time for objects place in the cache. Defaults to $EXPIRESNEVER if\nnot explicitly set.\n\n*autopurgeinterval*\nSets the auto purge interval. If this option is set to a particular time ( in the same\nformat as the expiresin ), then the purge( ) routine will be called during the first set\nafter the interval expires. The interval will then be reset.\n\n*autopurgeonset*\nIf this option is true, then the auto purge interval routine will be checked on every set.\n\n*autopurgeonget*\nIf this option is true, then the auto purge interval routine will be checked on every get.\n",
                "subsections": []
            },
            "PROPERTIES": {
                "content": "(get|set)namespace( )\nThe namespace of this cache instance\n",
                "subsections": [
                    {
                        "name": "get_default_expires_in",
                        "content": "The default expiration time for objects placed in this cache instance\n"
                    },
                    {
                        "name": "get_keys",
                        "content": "The list of keys specifying objects in the namespace associated with this cache instance\n"
                    },
                    {
                        "name": "get_identifiers",
                        "content": "This 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 particular time ( in the same\nformat as the expiresin ), then the purge( ) routine will be called during the first get\nafter the interval expires. The interval will then be reset.\n\n(get|set)autopurgeonset( )\nIf this property is true, then the auto purge interval routine will be checked on every set.\n\n(get|set)autopurgeonget( )\nIf this property is true, then the auto purge interval routine will be checked on every get.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "CHI - the successor to Cache::Cache\n\nCache::Object, Cache::MemoryCache, Cache::FileCache, Cache::SharedMemoryCache, and\nCache::SizeAwareFileCache\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Original author: DeWitt Clinton <dewitt@unto.net>\n\nLast author: $Author: dclinton $\n\nCopyright (C) 2001-2003 DeWitt Clinton\n",
                "subsections": []
            }
        }
    }
}