|* cache_root||Specify the top level directory to store cache and related files in. This parameter is required. Keep in mind that <B>Cache::BDBB> uses a <B>BerkeleyDBB> environment object so more than one file will be written for each cache.|
If you want to tell <B>Cache::BDBB> exactly which file to use for your
cache, specify it here. This paramater is required if you plan to use
the env_lock option and/or if you want to have multiple logical
databases (namespaces) in a single physical file. If unspecified,
<B>Cach::BDBB> will create its database file using the
<B>namespaceB>. <B>cache_fileB> should be relative to your cache_root, not
This gives you, among other files, /some/location/for/caching/whatever.db. Your logical database inside of whatever.db will be named with MyObject. If you were to then instantiate another Cache::BDB with the following:
Your <B>namespaceB> tells <B>Cache::BDBB> where to store cache data under
the <B>cache_rootB> if no <B>cache_fileB> is specified or what to call the
database in the multi-database file if <B>cache_fileB> is specified. It
is a required parameter. For clarity, it might be best to instantiate
<B>Cache::BDBB> objects like so:
Unlike the examples given above under cache_file, this allows you to locate a single cache type in its own directory, which gives you more flexibility to nuke it wholesale or move things around a little.
Cache::BDB allows you to select the type of Berkeley DB storage
mechanism to use. Your choices are Hash, Btree, and Recno. Queue isnt
supported. I havent tested the three supported types extensively. The
default, if unspecified, is Btree, and this is probably good enough
for most applications. Note that if a cache is created as one type it
must remain that type. If you instantiate a Cache::BDB object with one
type (or use the default), and then attempt to connect to the same
cache with a newly instantiated object that uses a different type, you
will get a warning, and Cache::BDB will be nice and connect you to the
cache with its original type.
Important: up until Berkeley DB 4.4.x, it has not been possible to shrink the physical size of a database file, which means that, technically, your cache files will never get smaller even if you delete everything from them. HOWEVER, with 4.4.x this functionality is now possiblye but it will only work with the Btree type. As soon as this is available in the BerkeleyDB.pm wrapper (soon Im told), Ill be releasing a version with some options to allow this. Point being, this may be a good reason to stick with Btree.
For more info, see http://www.sleepycat.com/docs/ref/am_conf/intro.html.
|* env_lock||If multiple databases (same or different files) are opened using the same Berkeley DB environment, its possible to turn on environment level locking rather than file level locking. This may be advantageous if you have two separate but related caches. By passing in the env_lock parameter with any true value, the environment will be created in such a way that any databases created under its control will all lock whenever Berkeley DB attempts a read/write lock. This flag must be specified for every database opened under this environment. Note: this is very untested in Cache::BDB, and I dont know how necessary it is.|
|* default_expires_in||Time (in seconds) that cached objects should live. If set to 0, objects never expire. See <B>setB> to enable a per-object value.|
|* auto_purge_interval||Time (in seconds) that the cached objects will be purged by one or both of the <B>auto_purgeB> types (get/set). If set to 0, auto purge is disabled. Note, of course, that objects wont actually be purged until some event actually takes place that will call purge (set or get), so if this is set to 300 but no gets or sets are called for more than 300 seconds, the items havent actually been purged yet.|
|* auto_purge_on_set||If this item is true and <B>auto_purge_intervalB> is greater than 0, calling the <B>setB> method will first purge any expired records from the cache.|
|* auto_purge_on_get||If this item is true and <B>auto_purge_intervalB> is greater than 0, calling the <B>getB> method will first purge any expired records from the cache.|
|* purge_on_init||If set to a true value, purge will be called before the constructor returns.|
|* purge_on_destroy||If set to a true value, purge will be called before the object goes out of scope.|
|* clear_on_init||If set to a true value, clear will be called before the constructor returns.|
|* clear_on_destroy||If set to a true value, clear will be called before the object goes out of scope.|
|* disable_compact||Disable database compactions for clear, purge, delete and remove methods. See <B>DATABASE SIZEB> below for more information on database compaction.|
|* disable_auto_purge||As a courtesy, Cache::BDB will automatically remove() any expired cache item you get() before returning undef. This is handy if you dont feel the need to do a lot of explicit cache purging, but if you only want purge, remove, delete or clear to actually delete cache items, you can disable this functionality by passing in disable_auto_purge with any true value.|
|<B>closeB>()||Explicitly close the connection to the cache. A good idea. Essentially the same as undefing the object (explicitly calls DESTROY).|
|<B>namespaceB>()||This read only method returns the namespace that the cache object is currently associated with.|
|<B>auto_purge_intervalB>($seconds)||Set/get the length of time (in seconds) that the cache object will wait before calling one or both of the <B>auto_purgeB> methodss. If set to 0, automatic purging is disabled.|
|<B>auto_purge_on_setB>(1/0)||Enable/disable auto purge when <B>setB> is called.|
|<B>auto_purge_on_getB>(1/0)||Enable/disable auto purge when <B>getB> is called.|
|<B>setB>($key, $value, [$seconds])||Store an item ($value) with the associated $key. Time to live (in seconds) can be optionally set with a third argument. Returns true on success.|
|<B>addB>($key, $value, [$seconds])||Only <B>setB> in the cache if the key doesnt already exist.|
|<B>replaceB>($key, $value, [$seconds])||Only <B>setB> in the cache if the key does exist.|
|<B>getB>($key)||Locate and return the data associated with $key. Returns the object associated with $key or undef if the data doesnt exist. If <B>auto_purge_on_getB> is enabled, the cache will be purged before attempting to locate the item.|
Returns a hash reference containing every unexpired item from the
cache keyed on their cache id. This can be useful if your keys arent
always available or if you just want to use the cache as a convenient
way to dump data in chunks.
The result looks something like this:
|<B>removeB>($key)||Removes the cache element specified by $key if it exists. Returns true for success.|
|<B>deleteB>($key)||Same as remove()|
|<B>clearB>()||Completely clear out the cache and compact the underlying database. Returns the number of cached items removed.|
|<B>countB>()||Returns the number of items in the cache.|
|<B>sizeB>()||Return the size (in bytes) of all the cached items. This call relies on the availability of <B>Devel::SizeB>. If its not found, youll get a warning and size() will simply return 0. Currently the size is calculated every time this is called by using <B>Devel::Size::total_sizeB>, so it may be expensive for large caches. In the future size-aware options and functionality may be available, but for now youll need to implement this outside of Cache::BDB if you need it.|
|<B>purgeB>()||Purge expired items from the cache. Returns the number of items purged.|
|<B>is_expiredB>($key)||Returns true if the data pointed to by $key is expired based on its stored expiration time. Returns false if the data isnt expired *or* if the data doesnt exist.|
Before Berkeley DB release 4.4 it was not possible to return freed space in a database file. This means that no matter how many items you delete, your file will still retain its size, and continue to grow as you add more items. The only way to get the file size back down was to dump the database to a file and reload it into a new database file. This may or may not be a problem for your application, but keep in mind that your cache will continue to get bigger and, for example, your operating system may have a maximum file size limit.
In 4.4, Sleepycat introduced the ability to free unused space. BerkeleyDB 0.29 exposes this functionality in the perl wrapper. If you are using these versions or better and have chosen the Btree database type (the default for Cache::BDB), your caches will automatically be compacted when items are purged, removed/deleted, or if clear is called. You can disable the automatic compaction of cache files by initializing your Cache::BDB object with the disable_compact parameter set to any true value. In my tests so far, however, database compaction does not appear to affect performance significantly, and may save you from a headache down the road.
Josh Rotenberg, <joshrotenberg at gmail.com>
* Make data storage scheme configurable (Storable, YAML, Data::Dumper,
or callback based)
* Add some size/count aware features.
* Create some examples.
* Fix fork()ing tests.
Please report any bugs or feature requests to bug-cache-bdb at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cache-BDB>. I will be notified, and then youll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
o AnnoCPAN: Annotated CPAN documentation o CPAN Ratings o RT: CPANs request tracker
o Search CPAN
Baldur Kristinsson Sandy Jensen
Copyright 2006 Josh Rotenberg, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 126: Expected text after =item, not a bullet Around line 133: Expected text after =item, not a bullet Around line 158: Expected text after =item, not a bullet Around line 174: Expected text after =item, not a bullet Around line 198: Expected text after =item, not a bullet Around line 211: Expected text after =item, not a bullet Around line 216: Expected text after =item, not a bullet Around line 225: Expected text after =item, not a bullet Around line 231: Expected text after =item, not a bullet Around line 237: Expected text after =item, not a bullet Around line 241: Expected text after =item, not a bullet Around line 246: Expected text after =item, not a bullet Around line 250: Expected text after =item, not a bullet Around line 255: Expected text after =item, not a bullet Around line 261: Expected text after =item, not a bullet
|perl v5.20.3||CACHE::BDB (3)||2006-07-21|