1 package Koha::Cache::Memory::Lite;
3 # Copyright 2016 Koha Development Team
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 Koha::Cache::Memory::Lite - Handling caching of objects in memory *only* for Koha
26 use Koha::Cache::Memory::Lite;
27 my $cache = Koha::Cache::Memory::Lite->get_instance();
28 $cache->set($key, $value);
29 my $retrieved_from_cache_value = $cache->get($key);
30 $cache->clear_from_cache($key);
35 Koha in memory only caching routines.
41 use base qw(Class::Accessor);
48 This gets a shared instance of the lite cache, set up in a very default
49 way. The lite cache is an in memory only cache that's automatically flushed
56 $singleton_cache = $class->new() unless $singleton_cache;
57 return $singleton_cache;
62 my $value = $cache->get_from_cache($key);
64 Retrieve the value stored under the specified key in the cache.
66 The retrieved value is a direct reference so should not be modified.
71 my ( $self, $key ) = @_;
72 return $L1_cache{$key};
77 $cache->set_in_cache($key, $value);
79 Save a value to the specified key in the cache.
84 my ( $self, $key, $value ) = @_;
85 $L1_cache{$key} = $value;
88 =head2 clear_from_cache
90 $cache->clear_from_cache($key);
92 Remove the value identified by the specified key from the lite cache.
96 sub clear_from_cache {
97 my ( $self, $key ) = @_;
98 delete $L1_cache{$key};
103 my @keys = $cache->all_keys();
105 Returns an array of all keys currently in the lite cache.
111 return keys %L1_cache;
118 Clear the entire lite cache.