ensembl-hive  2.8.1
SeqRegionCache.pm
Go to the documentation of this file.
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 
39 
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;
74 
75 package Bio::EnsEMBL::Utils::SeqRegionCache;
76 
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 
Bio::EnsEMBL::DBSQL::DBAdaptor
Definition: DBAdaptor.pm:40
Bio::EnsEMBL::Utils::SeqRegionCache
Definition: SeqRegionCache.pm:40
Bio::EnsEMBL::DBSQL::DBAdaptor::get_SeqRegionCache
public Bio::EnsEMBL::Utils::SeqRegionCache get_SeqRegionCache()
Bio::EnsEMBL::Utils::Cache
Definition: Cache.pm:71
about
public about()
Bio::EnsEMBL::DBSQL::DBAdaptor::new
public Bio::EnsEMBL::DBSQL::DBAdaptor new()