EnsEMBL/Utils/SeqRegionCache.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 19 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::Utils::SeqRegionCache - A shared LRU cache of information about
34 seq_regions
35  
36 =head1 SYNOPSIS
37  
38 use Bio::EnsEMBL::DBSQL::DBAdaptor;
39  
40 $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
41  
42 $seq_region_cache = $db->get_SeqRegionCache();
43  
44 $key = "$seq_region_name:$coord_system_id";
45  
46 $array = $seq_region_cache->{$key};
47  
48 if ($array) {
49 $name = $array->[1];
50 $length = $array->[3];
51 } else {
52 # cache miss, get the info from the database
53 # ...
54  
55 # cache the retrieved information
56 $seq_region_cache->{$key} = [
57 $seq_region_id, $seq_region_name,
58 $coord_system_id, $seq_region_length
59 ];
60 }
61  
62 =head1 DESCRIPTION
63  
64 This module is simply a convenient place to put a cache of sequence
65 region information which is shared by several adaptors for a given
66 database.
67  
68 =head1 METHODS
69  
70 =cut
71  
72 use strict;
73 use Bio::EnsEMBL::Utils::Cache;
74  
75 package Bio::EnsEMBL::Utils::SeqRegionCache;
76 $Bio::EnsEMBL::Utils::SeqRegionCache::VERSION = '114.0.0';
77 our $SEQ_REGION_CACHE_SIZE = 40000;
78  
79  
80  
81 sub new {
82 my $class = shift;
83  
84 my %id_cache;
85 my %name_cache;
86  
87 #
88 # the items to cache should be listrefs to
89 # [ sr_id, sr_name, cs_id, sr_length ]
90 #
91 # The name cache key is "sr_name:cs_id"
92 # The id cache is keyed on "sr_id"
93 #
94  
95 tie(%name_cache, 'Bio::EnsEMBL::Utils::Cache', $SEQ_REGION_CACHE_SIZE);
96 tie(%id_cache, 'Bio::EnsEMBL::Utils::Cache', $SEQ_REGION_CACHE_SIZE);
97  
98 return bless {'name_cache' => \%name_cache,
99 'id_cache' => \%id_cache}, $class;
100 }
101  
102  
103 1;
104  
105  
106  
107