AnyEvent-InMemoryCache

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# SYNOPSIS

    use AnyEvent;
    use AnyEvent::InMemoryCache;
    

    my $cache = AnyEvent::InMemoryCache->new;
    

    $cache->set(immortal => "Don't expire!");  # It lasts forever by default
    say $cache->get("immortal");  # "Don't expire!"
    

    $cache->set(a_second => "Expire soon", "1s");  # Expires in one-second.
    say $cache->get('a_second');  # "Expires soon"
    AE::timer 2, 0, sub{  # 2 seconds later
        $cache->exists('a_second');  # false
    };
    

    # You can overwrite key, and it's mortal now.
    $cache->set(immortal => 'will die...', "10min");
    

    # If you want a key not to be expired, pass negative integer for the third parameter.

lib/AnyEvent/InMemoryCache.pm  view on Meta::CPAN

AnyEvent::InMemoryCache - Simple in-memory cache for AnyEvent applications

=head1 SYNOPSIS

    use AnyEvent;
    use AnyEvent::InMemoryCache;
    
    my $cache = AnyEvent::InMemoryCache->new;
    
    $cache->set(immortal => "Don't expire!");  # It lasts forever by default
    say $cache->get("immortal");  # "Don't expire!"
    
    $cache->set(a_second => "Expire soon", "1s");  # Expires in one-second.
    say $cache->get('a_second');  # "Expires soon"
    AE::timer 2, 0, sub{  # 2 seconds later
        $cache->exists('a_second');  # false
    };
    
    # You can overwrite key, and it's mortal now.
    $cache->set(immortal => 'will die...', "10min");
    
    # If you want a key not to be expired, pass negative integer for the third parameter.
    $cache->set(immortal => 'Immortal again!', -1);
    



( run in 0.821 second using v1.01-cache-2.11-cpan-483215c6ad5 )