1CHI::Driver::RawMemory(U3s)er Contributed Perl DocumentatCiHoIn::Driver::RawMemory(3)
2
3
4
6 CHI::Driver::RawMemory - In-process memory cache that stores direct
7 references
8
10 version 0.60
11
13 use CHI;
14
15 my $hash = {};
16 my $cache = CHI->new( driver => 'RawMemory', datastore => $hash );
17
18 my $cache = CHI->new( driver => 'RawMemory', global => 1 );
19
20 my $cache = CHI->new( driver => 'RawMemory', global => 0 );
21
23 This is a subclass of CHI::Driver::Memory that stores references to
24 data structures directly instead of serializing / deserializing. This
25 makes the cache faster at getting and setting complex data structures,
26 but unlike most drivers, modifications to the original data structure
27 will affect the data structure stored in the cache, and vice versa.
28 e.g.
29
30 my $cache = CHI->new( driver => 'Memory', global => 1 );
31 my $lst = ['foo'];
32 $cache->set('key' => $lst); # serializes $lst before storing
33 $cache->get('key'); # returns ['foo']
34 $lst->[0] = 'bar';
35 $cache->get('key'); # returns ['foo']
36
37 my $cache = CHI->new( driver => 'RawMemory', global => 1 );
38 my $lst = ['foo'];
39 $cache->set('key' => $lst); # stores $lst directly
40 $cache->get('key'); # returns ['foo']
41 $lst->[0] = 'bar';
42 $cache->get('key'); # returns ['bar']!
43
45 Same as CHI::Driver::Memory.
46
48 For the purpose of size-awareness, all items count as size 1 for this
49 driver. (Because data structures are not serialized, there's no good
50 way to determine their size.)
51
52 # Keep a maximum of 10 items in cache
53 #
54 my $cache = CHI->new( driver => 'RawMemory', datastore => {}, max_size => 10 );
55
57 Thanks to Yuval Kogman whose Cache::Ref inspired me to do this.
58
60 CHI::Driver::Memory, CHI
61
63 Jonathan Swartz <swartz@pobox.com>
64
66 This software is copyright (c) 2012 by Jonathan Swartz.
67
68 This is free software; you can redistribute it and/or modify it under
69 the same terms as the Perl 5 programming language system itself.
70
71
72
73perl v5.32.0 2020-07-28 CHI::Driver::RawMemory(3)