The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Cache::Memory::Simple - Yet another on memory cache

SYNOPSIS

    use Cache::Memory::Simple;
    use feature qw/state/;

    sub get_stuff {
        my ($class, $key) = @_;

        state $cache = Cache::Memory::Simple->new();
        $cache->get_or_set(
            $key, sub {
                Storage->get($key) # slow operation
            }, 10 # cache in 10 seconds
        );
    }

DESCRIPTION

Cache::Memory::Simple is yet another on memory cache implementation.

METHODS

my $obj = Cache::Memory::Simple->new()

Create a new instance.

my $stuff = $obj->get($key);

Get a stuff from cache storage by $key

$obj->set($key, $val, $expiration)

Set a stuff for cache.

$obj->delete($key)

Delete key from cache.

$obj->purge()

Purge expired data.

This module does not purge expired data automatically. You need to call this method if you need.

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>

SEE ALSO

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.