logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

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

Acknowledgments

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

Author

       Jonathan Swartz <swartz@pobox.com>

Constructor Options

       Same as CHI::Driver::Memory.

Description

       This is a subclass of CHI::Driver::Memory that stores references to data structures directly instead of
       serializing / deserializing.  This makes the cache faster at getting and setting complex data structures,
       but unlike most drivers, modifications to the original data structure will affect the data structure
       stored in the cache, and vice versa. e.g.

           my $cache = CHI->new( driver => 'Memory', global => 1 );
           my $lst = ['foo'];
           $cache->set('key' => $lst);   # serializes $lst before storing
           $cache->get('key');   # returns ['foo']
           $lst->[0] = 'bar';
           $cache->get('key');   # returns ['foo']

           my $cache = CHI->new( driver => 'RawMemory', global => 1 );
           my $lst = ['foo'];
           $cache->set('key' => $lst);   # stores $lst directly
           $cache->get('key');   # returns ['foo']
           $lst->[0] = 'bar';
           $cache->get('key');   # returns ['bar']!

Name

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

See Also

       CHI::Driver::Memory, CHI

Size Awareness

       For the purpose of size-awareness, all items count as size 1 for this driver. (Because data structures
       are not serialized, there's no good way to determine their size.)

           # Keep a maximum of 10 items in cache
           #
           my $cache = CHI->new( driver => 'RawMemory', datastore => {}, max_size => 10 );

Synopsis

           use CHI;

           my $hash = {};
           my $cache = CHI->new( driver => 'RawMemory', datastore => $hash );

           my $cache = CHI->new( driver => 'RawMemory', global => 1 );

           my $cache = CHI->new( driver => 'RawMemory', global => 0 );

Version

       version 0.61

See Also