ensembl-hive  2.8.1
Bio::EnsEMBL::DBSQL::Support::BaseCache Class Reference
+ Inheritance diagram for Bio::EnsEMBL::DBSQL::Support::BaseCache:

Public Member Functions

public Bio::EnsEMBL::DBSQL::Support::BaseCache new ()
 
public Bio::EnsEMBL::DBSQL::BaseAdaptor adaptor ()
 
public Hash cache ()
 
public void delete_cache ()
 
public Scalar get ()
 
public ArrayRef get_by_list ()
 
public ArrayRef get_by_sql ()
 
public Scalar put ()
 
public Scalar remove ()
 
public void clear_cache ()
 
public List cache_keys ()
 
public List cached_values ()
 
public Int size ()
 
public Hash build_cache ()
 

Detailed Description

Synopsis

package Cache;
return {}; #sends back a very basic cache which is a hash
}
1;
#In use
$cache->put(1, 'a');
is($cache->get(1), 'a');
is($cache->put(1, 'b'), 'a'); #put returns the object it replaced
is($cache->delete(1), 'b'); #delete returns the object it removed
is_deeply([$cache->cache_keys()], [1]);
$cache->clear_cache();
is($cache->size(), 0);
#Try using SQL - cache will be consulted accordingly
my $ids = $cache->get_by_sql('select dbid from table where val like ?', ['someval%']);

Description

A base class used for holding methods common to all cache implementations. 
Never use this class to do direct caching instead use one of the following

=over 8

=item Bio::EnsEMBL::DBSQL::Support::LruIdCache

=item Bio::EnsEMBL::DBSQL::Support::FullIdCache

=back

To provide exta functionality to the caches you should override one of the above
classes and extend. Caches work when you use inheritence by composition in their
target adaptor.

Definition at line 55 of file BaseCache.pm.

Member Function Documentation

◆ adaptor()

public Bio::EnsEMBL::DBSQL::BaseAdaptor Bio::EnsEMBL::DBSQL::Support::BaseCache::adaptor ( )
  Arg [1]    : Bio::EnsEMBL::DBSQL::BaseAdaptor $db_adaptor
  Description: Getter setter for the adaptor this serves as an ID cacher for
  Returntype : Bio::EnsEMBL::DBSQL::BaseAdaptor
  Exceptions : none
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ build_cache()

public Hash Bio::EnsEMBL::DBSQL::Support::BaseCache::build_cache ( )
  Description: Implement to return the required type of cache
  Returntype : Hash
  Exceptions : None
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ cache()

public Hash Bio::EnsEMBL::DBSQL::Support::BaseCache::cache ( )
  Description: Returns back a Hash implementing object and also calls 
               build_cache() for an initialise on demand system
  Returntype : Hash
  Exceptions : none
  Caller     : BaseAdaptors and internal
  Status     : Beta
 
Code:
click to view

◆ cache_keys()

public List Bio::EnsEMBL::DBSQL::Support::BaseCache::cache_keys ( )
  Example    :
my @keys = $cache->cache_keys();
  Description: Returns all keys held by the cache
  Returntype : List of all available keys
  Exceptions : None
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ cached_values()

public List Bio::EnsEMBL::DBSQL::Support::BaseCache::cached_values ( )
  Example    :
my @values = $cache->cached_values();
  Description: Returns all values held by the cache
  Returntype : List of all available values
  Exceptions : None
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ clear_cache()

public void Bio::EnsEMBL::DBSQL::Support::BaseCache::clear_cache ( )
  Example    :
$cache->clear_cache();
  Description: Removes all values from the cache but does not delete the cache
               instance
  Returntype : None
  Exceptions : None
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ delete_cache()

public void Bio::EnsEMBL::DBSQL::Support::BaseCache::delete_cache ( )
  Example    :
$cache->delete_cache();
  Description: Deletes the cache. Normally used to trigger a build_cache() 
               call
  Returntype : none
  Exceptions : none
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ get()

public Scalar Bio::EnsEMBL::DBSQL::Support::BaseCache::get ( )
  Arg [1]    : String key to retrieve
  Example    :
$cache->put(1,'a'); is($cache->get(1), 'a');
  Description: Retrieves the value held in the cache. Can return undef if the
               value could not be found
  Returntype : Scalar value held in the cache or nothing
  Exceptions : If key was undefined
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ get_by_list()

public ArrayRef Bio::EnsEMBL::DBSQL::Support::BaseCache::get_by_list ( )
  Arg [1]    : ArrayRef keys to retrieve
  Example    :
is($cache->get_by_list([1,2]), ['a','b']);
  Description: Retrieves the values held in the cache. If a key cannot be
               found you get no entry in the resulting array returned.
  Returntype : ArrayRef of found values
  Exceptions : If the given ArrayRef was undefined
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ get_by_sql()

public ArrayRef Bio::EnsEMBL::DBSQL::Support::BaseCache::get_by_sql ( )
  Arg [1]    : String SQL to execute. Should return the key of this cache in column 1
  Arg [2]    : ArrayRef Parameters to bind to the specified query
  Example    :
$cache->get_by_sql('select id from tables where p like ?', ['val%']);
  Description: Executes the given SQL statement against the construnction adaptor's
               backing database. The found IDs are then passed into get_by_list()
               where the elements are returned should the cache hold them.
               Remember if the cache is un-aware of the key or the specific 
               implementation used cannot perform database lookups based on cache misses
               you will not be able to retrieve the object in question.
  Returntype : ArrayRef of found values
  Exceptions : Thrown if SQL and parameters are empty and not the expected types. All
               other exceptions come from DBI/SQL operations.
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ new()

public Bio::EnsEMBL::DBSQL::Support::BaseCache Bio::EnsEMBL::DBSQL::Support::BaseCache::new ( )
  Arg [1]    : Bio::EnsEMBL::DBSQL::BaseAdaptor $db_adaptor
  Example    :
$cache = CacheInheritedFromBaseCache->new($db_adaptor);
  Description: Creates a new cache class which handles all the basics of
               working with a cache apart from what that cache implementation
               is (apart from a hash)
  Returntype : Bio::EnsEMBL::DBSQL::Support::BaseCache
  Exceptions : none
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ put()

public Scalar Bio::EnsEMBL::DBSQL::Support::BaseCache::put ( )
  Arg [1]    : String key to store
  Arg [2]    : Scalar value to store
  Example    :
$cache->put(2, 'b');
  Description: Stores a value in the cache. Returns the previous value held 
               under that key if one existed
  Returntype : Scalar of the previously held value if one existed
  Exceptions : If key was undefined
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ remove()

public Scalar Bio::EnsEMBL::DBSQL::Support::BaseCache::remove ( )
  Arg [1]    : String key to remove
  Example    :
is($cache->remove(1), 'a');
  Description: Removes the supplied key from the cache
  Returntype : Scalar value held in the cache or nothing
  Exceptions : If key was undefined
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

◆ size()

public Int Bio::EnsEMBL::DBSQL::Support::BaseCache::size ( )
  Example    :
$cache->size();
  Description: Returns the number of keys currrently held by the cache
  Returntype : Int $size
  Exceptions : None
  Caller     : BaseAdaptors
  Status     : Beta
 
Code:
click to view

The documentation for this class was generated from the following file:
Bio::EnsEMBL::DBSQL::Support::BaseCache::remove
public Scalar remove()
Bio::EnsEMBL::DBSQL::Support::BaseCache::clear_cache
public void clear_cache()
Bio::EnsEMBL::DBSQL::Support::BaseCache::delete_cache
public void delete_cache()
Bio::EnsEMBL::DBSQL::Support::BaseCache
Definition: BaseCache.pm:55
Bio::EnsEMBL::DBSQL::Support::BaseCache::build_cache
public Hash build_cache()
Bio::EnsEMBL::DBSQL::Support::BaseCache::get_by_sql
public ArrayRef get_by_sql()
Bio::EnsEMBL::DBSQL::Support::BaseCache::adaptor
public Bio::EnsEMBL::DBSQL::BaseAdaptor adaptor()
Bio::EnsEMBL::DBSQL::Support::BaseCache::put
public Scalar put()
Bio::EnsEMBL::DBSQL::Support::BaseCache::cache
public Hash cache()
Bio::EnsEMBL::DBSQL::Support::BaseCache::size
public Int size()
Bio::EnsEMBL::DBSQL::Support::BaseCache::cached_values
public List cached_values()
Bio::EnsEMBL::DBSQL::Support::BaseCache::get_by_list
public ArrayRef get_by_list()
Bio::EnsEMBL::DBSQL::Support::BaseCache::get
public Scalar get()
Bio::EnsEMBL::DBSQL::Support::BaseCache::cache_keys
public List cache_keys()