Archive Ensembl HomeArchive Ensembl Home
Bio::EnsEMBL::Utils::Cache Class Reference

List of all members.


Class Summary

Synopsis

 use Tie::Cache;
 tie %cache, 'Tie::Cache', 100, { Debug =\> 1 };   
 tie %cache2, 'Tie::Cache', { MaxCount =\> 100, MaxBytes =\> 50000 };
 tie %cache3, 'Tie::Cache', 100, { Debug =\> 1 , WriteSync =\> 0};   

 # Options ##################################################################
 #
 # Debug =\>     0 - DEFAULT, no debugging output
 #       1 - prints cache statistics upon destroying
 #       2 - prints detailed debugging info
 #
 # MaxCount =\>  Maximum entries in cache.
 #
 # MaxBytes =\>   Maximum bytes taken in memory for cache based on approximate 
 #               size of total cache structure in memory
 #
 #               There is approximately 240 bytes used per key/value pair in the cache for 
 #               the cache data structures, so a cache of 5000 entries would take
 #               at approximately 1.2M plus the size of the data being cached.
 #
 # MaxSize  =\>   Maximum size of each cache entry. Larger entries are not cached.
 #                   This helps prevent much of the cache being flushed when 
 #                   you set an exceptionally large entry.  Defaults to MaxBytes/10
 #
 # WriteSync =\>  1 - DEFAULT, write() when data is dirtied for 
 #                   TRUE CACHE (see below)
 #               0 - write() dirty data as late as possible, when leaving 
 #                   cache, or when cache is being DESTROY'd
 #
 ############################################################################

 # cache supports normal tied hash functions
 $cache{1} = 2;       # STORE
 print "$cache{1}\n"; # FETCH

 # FIRSTKEY, NEXTKEY
 while(($k, $v) = each %cache) { print "$k: $v\n"; } 
 
 delete $cache{1};    # DELETE
 %cache = ();         # CLEAR

Description

This module implements a least recently used (LRU) cache in memory
through a tie interface.  Any time data is stored in the tied hash,
that key/value pair has an entry time associated with it, and 
as the cache fills up, those members of the cache that are
the oldest are removed to make room for new entries.
So, the cache only "remembers" the last written entries, up to the 
size of the cache.  This can be especially useful if you access 
great amounts of data, but only access a minority of the data a 
majority of the time.
The implementation is a hash, for quick lookups, 
overlaying a doubly linked list for quick insertion and deletion.
On a WinNT PII 300, writes to the hash were done at a rate 
3100 per second, and reads from the hash at 6300 per second.   
Work has been done to optimize refreshing cache entries that are 
frequently read from, code like $cache{entry}, which moves the 
entry to the end of the linked list internally.
 

Definition at line 71 of file Cache.pm.

Available Methods

protected _get_data_length ()
public CLEAR ()
public create_node ()
public DELETE ()
public delete ()
public DESTROY ()
public EXISTS ()
public FETCH ()
public FIRSTKEY ()
public flush ()
public insert ()
public NEXTKEY ()
public pretty_chains ()
public pretty_self ()
public print ()
public read ()
public STORE ()
public TIEHASH ()
public write ()

Method Documentation

protected Bio::EnsEMBL::Utils::Cache::_get_data_length ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::CLEAR ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::create_node ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::DELETE ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::delete ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::DESTROY ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::EXISTS ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::FETCH ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::FIRSTKEY ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::flush ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::insert ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::NEXTKEY ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::pretty_chains ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::pretty_self ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::print ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::read ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::STORE ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::TIEHASH ( )

Undocumented method

Code:
click to view
public Bio::EnsEMBL::Utils::Cache::write ( )

Undocumented method

Code:
click to view

The documentation for this class was generated from the following file: