Cache::FileCache Thoughts

If using perl Cache::FileCache, some comments offering a helpful starting point to get a cache that works in a relatively well behaved and unsurprising way:

use Cache::FileCache;
use File::Spec;

my $cache = Cache::FileCache->new({
    # "The namespace associated with this
    # cache."
    namespace => 'BJD-TESTING-app_id_cache_id',
    # "The default expiration time for
    # objects place in the cache."
    # This is in seconds.
    default_expires_in => 1,
    # "Sets the auto purge interval. If this
    # option is set to a particular time ( in
    # the same format as the expires_in ),
    # then the purge( ) routine will be
    # called during the first set after the
    # interval expires. The interval will
    # then be reset."
    #
    # XXX To work needs at least one of
    # auto_purge_on_set or auto_purge_on_get
    # to be set to true
    auto_purge_interval => 5,
    auto_purge_on_set => 1,
    # restrict access to the cache to just this
    # user (data security)
    #
    # NOTE that if you set directory_umask
    # but no cache_root you can end up clashing
    # with other users who will also be trying
    # to use (and maybe set the umask) on
    # /tmp/FileCache
    #
    # If we care about data security set
    # cache_root as well to put the files in
    # out own private directory:
    directory_umask => 0077,
    cache_root =>
      File::Spec->tmpdir()
      . "/bjdean-perl-Cache-FileCache",
});

Leave a Reply

Your email address will not be published. Required fields are marked *