perl — кэширование

Модули Perl для организации кэширования данных - CHI, Cache::Cache

CHI - Unified cache handling interface

https://metacpan.org/release/CHI

my $customer = $cache->get($name);
if ( !defined $customer ) {
    $customer = get_customer_from_db($name);
    $cache->set( $name, $customer, "10 minutes" );
}
my $customer2 = $cache->compute($name2, "10 minutes", sub {
    get_customer_from_db($name2)
});
$cache->remove($name);

Cache::Cache -- the Cache interface

https://metacpan.org/pod/Cache::Cache

use Cache::FileCache;
my $cache = new Cache::FileCache( );
my $customer = $cache->get( $name );
if ( not defined $customer ){
    $customer = get_customer_from_db( $name );
    $cache->set( $name, $customer, "10 minutes" );
}

Leave a Reply