Tie::Cache::Autoupdater ----------------------- A tied hash whose values refresh themselves on a timeout. Long-running processes - FastCGI workers, daemons, queue consumers - often need data that changes rarely, but not never: site settings, row counters, a price list, a feature flag. Fetching it from the database on every request is wasteful, and fetching it once at start-up is wrong, because the process may stay alive for days while the data behind it changes every few minutes. This module ties a hash to a set of named data sources. You register a key with a subroutine and a timeout, and from then on reading that key gives you the cached value until the timeout expires; the first read after that calls the subroutine again and caches the new result. use Tie::Cache::Autoupdater; tie my %cache, 'Tie::Cache::Autoupdater', settings => { source => \&read_settings_from_db, timeout => 60 }, counters => { source => \&count_table_rows, timeout => 10 }; my $settings = $cache{settings}; See the module documentation for the full description: perldoc Tie::Cache::Autoupdater REQUIREMENTS ------------ Perl and the core modules Storable and, optionally, Time::HiRes - the latter is used for fractional timeouts when it is available. Tested on perl 5.26 through 5.42. HOW TO BUILD ------------ perl Makefile.PL make make test HOW TO INSTALL -------------- make install COPYRIGHT --------- Copyright 2011-2026 by Anton Morozov (antonfin) This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See the LICENSE file for the full text.