Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

Hey::Cache
Cache data multiple data structures

Hey::Cache - Cache data multiple data structures



NAME

Hey::Cache - Cache data multiple data structures


SYNOPSIS


  use Hey::Cache;

  

  my $cache = Hey::Cache->new(

      Namespace => 'WeatherApp2000',            # string (optional, default='default')

      CacheFile => 'fun_cache_file.xml',        # file path and name (optional, default='cache.xml')

      AutoSync => 1,                            # boolean (optional, default=1)

      Expires => 300,                           # seconds (optional, default=86400)

  );

  

  $cache->set(

      Name => '98501',                          # sets the name/key of the piece of data

      Value => { Temperature => 17,             # sets the data that you wish to cache

                 Condition => 'Rain',

                 High => 19,

                 Low => 7 },

      Expires => 600,                           # optional, defaults to what was set in the constructor above

  );

  $value = $cache->get( Name => '98501' );      # returns what you had set

  

  ... enough time passes (at least 10 minutes, according to the "Expires" value) ...

  

  $value = $cache->get( Name => '98501' );      # returns undef because it has expired

  

  $value = $cache->get( Name => '98501', Expires => 86400 );    # returns what you had set

                                                                # because it is newer than a day


DESCRIPTION

Helps with regular data caching. It's targetted for items that are in hash references, primarly.

new


  my $cache = Hey::Cache->new(

      Namespace => 'WeatherApp2000',            # string (optional, default='default')

      CacheFile => 'fun_cache_file.xml',        # file path and name (optional, default='cache.xml')

      AutoSync => 1,                            # boolean (optional, default=1)

      Expires => 300,                           # seconds (optional, default=86400)

  );

Namespace [optional]

Default value is ``default''.

CacheFile [optional]

Default value is ``cache.xml''.

AutoSync [optional]

Default value is 1.

Expires [optional]

Default value is 86400 (24 hours).

sync


  $cache->sync;

Sends the data out to file. If AutoSync is disabled (per call or in the constructor), this will manually save out your data to the cache file. If AutoSync is enabled, this will happen automatically.

get


  $weather = $cache->get( Name => '98501' );

  $weather = $cache->get( Name => '98501', Expires => 600 ); # override the expiration of the item

Gets the named data from the cache.

Name [required]

The name of the item to return. This name was specified in the $cache->set function.

Expires [optional]

Age in number of seconds that would be acceptable. If the cached item is newer than this value, it will return the item. If the cached item is older than the value, it will return undef.

set


  $value = { Temperature => 14, High => 15, Low => 12 };

  $cache->get( Name => '98501', Value => $value );

Set a value (scalar, hash, etc) by name into the cache.

Name [required]

The name. Name of the item. Use this as a key to get it later with the $cache->get function.

Value [required]

The value. It works best if it's a reference to something, especially a hash.

Sync [optional]

Boolean. Defaults to the value specified in the constructor, which defaults to true.

Timestamp [optional]

Defaults to the current time. If it is useful to set a different timestamp, you can do it here. This value is in epoch seconds.

Expires [optional]

Defaults to the value specified in the constructor. Sets the expiration time for this item. Expiration is stored with each item separately, so you can assign different expirations for different items.


AUTHOR

Dusty Wilson, <hey-cache-module@dusty.hey.nu>


COPYRIGHT AND LICENSE

Copyright (C) 2006 by Dusty Wilson <http://dusty.hey.nu/>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy