1CHI::Driver::RawMemory(U3s)er Contributed Perl DocumentatCiHoIn::Driver::RawMemory(3)
2
3
4

NAME

6       CHI::Driver::RawMemory - In-process memory cache that stores direct
7       references
8

VERSION

10       version 0.44
11

SYNOPSIS

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

DESCRIPTION

21       This is a subclass of CHI::Driver::Memory that stores references to
22       data structures directly instead of serializing / deserializing.  This
23       makes the cache faster at getting and setting complex data structures,
24       but unlike most drivers, modifications to the original data structure
25       will affect the data structure stored in the cache, and vica versa.
26       e.g.
27
28           my $cache = CHI->new( driver => 'Memory', global => 1 );
29           my $lst = ['foo'];
30           $cache->set('key' => $lst);   # serializes $lst before storing
31           $cache->get('key');   # returns ['foo']
32           $lst->[0] = 'bar';
33           $cache->get('key');   # returns ['foo']
34
35           my $cache = CHI->new( driver => 'RawMemory', global => 1 );
36           my $lst = ['foo'];
37           $cache->set('key' => $lst);   # stores $lst directly
38           $cache->get('key');   # returns ['foo']
39           $lst->[0] = 'bar';
40           $cache->get('key');   # returns ['bar']!
41

CONSTRUCTOR OPTIONS

43       Same as CHI::Driver::Memory.
44

SIZE AWARENESS

46       For the purpose of size-awareness, all items count as size 1 for this
47       driver. (Because data structures are not serialized, there's no good
48       way to determine their size.)
49
50           # Keep a maximum of 10 items in cache
51           #
52           my $cache = CHI->new( driver => 'RawMemory', datastore => {}, max_size => 10 );
53

ACKNOWLEDGEMENTS

55       Thanks to Yuval Kogman whose Cache::Ref inspired me to do this.
56

SEE ALSO

58       CHI::Driver::Memory, CHI
59

AUTHOR

61       Jonathan Swartz <swartz@pobox.com>
62
64       This software is copyright (c) 2011 by Jonathan Swartz.
65
66       This is free software; you can redistribute it and/or modify it under
67       the same terms as the Perl 5 programming language system itself.
68
69
70
71perl v5.12.3                      2011-03-17         CHI::Driver::RawMemory(3)
Impressum