ensembl-hive  2.8.1
Bio::EnsEMBL::Utils::Cache Class Reference

Public Member Functions

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

Detailed Description

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.

Member Function Documentation

◆ _get_data_length()

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

Undocumented method

Code:
click to view

◆ CLEAR()

public Bio::EnsEMBL::Utils::Cache::CLEAR ( )

Undocumented method

Code:
click to view

◆ create_node()

public Bio::EnsEMBL::Utils::Cache::create_node ( )

Undocumented method

Code:
click to view

◆ DELETE()

public Bio::EnsEMBL::Utils::Cache::DELETE ( )

Undocumented method

Code:
click to view

◆ delete()

public Bio::EnsEMBL::Utils::Cache::delete ( )

Undocumented method

Code:
click to view

◆ DESTROY()

public Bio::EnsEMBL::Utils::Cache::DESTROY ( )

Undocumented method

Code:
click to view

◆ EXISTS()

public Bio::EnsEMBL::Utils::Cache::EXISTS ( )

Undocumented method

Code:
click to view

◆ FETCH()

public Bio::EnsEMBL::Utils::Cache::FETCH ( )

Undocumented method

Code:
click to view

◆ FIRSTKEY()

public Bio::EnsEMBL::Utils::Cache::FIRSTKEY ( )

Undocumented method

Code:
click to view

◆ flush()

public Bio::EnsEMBL::Utils::Cache::flush ( )

Undocumented method

Code:
click to view

◆ insert()

public Bio::EnsEMBL::Utils::Cache::insert ( )

Undocumented method

Code:
click to view

◆ NEXTKEY()

public Bio::EnsEMBL::Utils::Cache::NEXTKEY ( )

Undocumented method

Code:
click to view

◆ pretty_chains()

public Bio::EnsEMBL::Utils::Cache::pretty_chains ( )

Undocumented method

Code:
click to view

◆ pretty_self()

public Bio::EnsEMBL::Utils::Cache::pretty_self ( )

Undocumented method

Code:
click to view

◆ print()

public Bio::EnsEMBL::Utils::Cache::print ( )

Undocumented method

Code:
click to view

◆ read()

public Bio::EnsEMBL::Utils::Cache::read ( )

Undocumented method

Code:
click to view

◆ STORE()

public Bio::EnsEMBL::Utils::Cache::STORE ( )

Undocumented method

Code:
click to view

◆ TIEHASH()

public Bio::EnsEMBL::Utils::Cache::TIEHASH ( )

Undocumented method

Code:
click to view

◆ write()

public Bio::EnsEMBL::Utils::Cache::write ( )

Undocumented method

Code:
click to view

The documentation for this class was generated from the following file:
Bio::EnsEMBL::Utils::Cache::pretty_chains
public pretty_chains()
Bio::EnsEMBL::Utils::Cache::print
public print()
Bio::EnsEMBL::Utils::Cache::flush
public flush()
Bio::EnsEMBL::Utils::Cache::insert
public insert()
Bio::EnsEMBL::Utils::Cache::FETCH
public FETCH()
Bio::EnsEMBL::Utils::Cache::NEXTKEY
public NEXTKEY()
Bio::EnsEMBL::Utils::Cache::STORE
public STORE()
Bio::EnsEMBL::Utils::Cache::DESTROY
public DESTROY()
Bio::EnsEMBL::Utils::Cache::CLEAR
public CLEAR()
Bio::EnsEMBL::Utils::Cache::EXISTS
public EXISTS()
Bio::EnsEMBL::Utils::Cache::write
public write()
Bio::EnsEMBL::Utils::Cache::_get_data_length
protected _get_data_length()
Bio::EnsEMBL::Utils::Cache::pretty_self
public pretty_self()
Bio::EnsEMBL::Utils::Cache::create_node
public create_node()
Bio::EnsEMBL::Utils::Cache::DELETE
public DELETE()
Bio::EnsEMBL::Utils::Cache::TIEHASH
public TIEHASH()
Bio::EnsEMBL::Utils::Cache::FIRSTKEY
public FIRSTKEY()
Bio::EnsEMBL::Utils::Cache::read
public read()