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::LruIdCache - ID based caching using an LRU backed cache
SYNOPSIS
my $cache = Bio::EnsEMBL::DBSQL::Support::LruIdCache->new($adaptor, 2);
my $obj = $cache->put(1, 'a');
my $obj = $cache->put(2, 'b');
my $obj = $cache->put(3, 'c');
is_deeply([$cache->cache_keys()], ['b','c']); #ID 1 was ejected under LRU rules
DESCRIPTION
An implementation of caching which uses the oldest accessed key as the value to be ejected from the cache when the maximum size has been hit. See the following page for more information about this algorithm
http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
METHODS
new
Arg [1] : Bio::EnsEMBL::DBSQL::BaseAdaptor $db_adaptor
Arg [2] : Int size of the cache. Defaults to 1000
Example : my $cache = Bio::EnsEMBL::DBSQL::Support::LruIdCache->new($db_adaptor, 10);
Description: Creates a new cache class instance
Returntype : Bio::EnsEMBL::DBSQL::Support::BaseCache
Exceptions : none
Caller : BaseAdaptors
Status : Beta
lru_size
Arg [1] : Int size of the cache
Example : $cache->lru_size(10);
Description: Resets the size of the cache and forces a rebuild of the cache
object to apply this new sizing. Also functions as a getter
Returntype : Int
Exceptions : none
Caller : BaseAdaptors
Status : Beta
build_cache
Description: Returns an instance of C<Bio::EnsEMBL::Utils::Cache> and sized
according to the return value in C<lru_cache()>
Returntype : Bio::EnsEMBL::Utils::Cache
Exceptions : none
Caller : BaseAdaptors
Status : Beta
get
Arg [1] : String key to retrieve
Example : $is($cache->get(1), 'a');
Description: Retrieves the value held in the cache. If the value is not in
the cache we will retrieve the value from
C<_uncached_fetch_by_dbID> and then store that value
Returntype : Scalar value held in the cache or nothing if the ID was not present
Exceptions : If key was undefined
Caller : BaseAdaptors
Status : Beta
get_by_list
Arg [1] : ArrayRef keys to retrieve
Arg [2] : Bio::EnsEMBL::Slice optional attribute for
C<_uncached_fetch_all_by_dbID_list()> delegation
Example : is($cache->get_by_list([1,2]), ['a','b']);
Description: Attempts to retrieve all values currently available in the cache,
fetches any remaining values and stores these in the cache.
Returntype : ArrayRef of found values
Exceptions : None
Caller : BaseAdaptors
Status : Beta