Bug 23580: Add C4::Context->yaml_preference
[koha.git] / Koha / Cache / Memory / Lite.pm
blob74e4115e68edef4deb2060aa10749eecf6aff3fd
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>.
20 =head1 NAME
22 Koha::Cache::Memory::Lite - Handling caching of objects in memory *only* for Koha
24 =head1 SYNOPSIS
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);
31 $cache->flush();
33 =head1 DESCRIPTION
35 Koha in memory only caching routines.
37 =cut
39 use Modern::Perl;
41 use base qw(Class::Accessor);
43 our %L1_cache;
45 our $singleton_cache;
46 sub get_instance {
47 my ($class) = @_;
48 $singleton_cache = $class->new() unless $singleton_cache;
49 return $singleton_cache;
52 sub get_from_cache {
53 my ( $self, $key ) = @_;
54 return $L1_cache{$key};
57 sub set_in_cache {
58 my ( $self, $key, $value ) = @_;
59 $L1_cache{$key} = $value;
62 sub clear_from_cache {
63 my ( $self, $key ) = @_;
64 delete $L1_cache{$key};
67 sub flush {
68 my ( $self ) = @_;
69 %L1_cache = ();