LICENSE
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute Copyright [2016-2024] EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
CONTACT
Please email comments or questions to the public Ensembl
developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
Questions may also be sent to the Ensembl help desk at
<http://www.ensembl.org/Help/Contact>.
NAME
Bio::EnsEMBL::DBSQL::Support::BaseCache - Base cache code
SYNOPSIS
package Cache;
use base qw/Bio::EnsEMBL::DBSQL::Support::BaseCache/;
sub build_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
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.
METHODS
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
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
cache
Description: Returns back a Hash implementing object and also calls
C<build_cache()> for an initialise on demand system
Returntype : Hash
Exceptions : none
Caller : BaseAdaptors and internal
Status : Beta
delete_cache
Example : $cache->delete_cache();
Description: Deletes the cache. Normally used to trigger a C<build_cache()>
call
Returntype : none
Exceptions : none
Caller : BaseAdaptors
Status : Beta
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
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
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 C<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
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
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
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
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
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
size
Example : $cache->size();
Description: Returns the number of keys currrently held by the cache
Returntype : Int $size
Exceptions : None
Caller : BaseAdaptors
Status : Beta
build_cache
Description: Implement to return the required type of cache
Returntype : Hash
Exceptions : None
Caller : BaseAdaptors
Status : Beta