NAME
Dancer2::Plugin::ContentCache::Driver - Storage abstraction role for Dancer2::Plugin::ContentCache
VERSION
version 1.0000
SYNOPSIS
package MyApp::ContentCache::Driver::Redis;
use v5.20;
use warnings;
use Moo;
with 'Dancer2::Plugin::ContentCache::Driver';
has plugin => ( is => 'ro', required => 1, weak_ref => 1 );
sub has_aging_columns { 1 }
sub has_created_column { 1 }
sub create_entry { my ($self, %entry) = @_; ... }
sub find_entry { my ($self, $uuid) = @_; ... }
sub delete_expired { my ($self) = @_; ... }
1;
# In config.yml:
plugins:
ContentCache:
driver: MyApp::ContentCache::Driver::Redis
DESCRIPTION
Dancer2::Plugin::ContentCache never talks to a database directly. Instead, it delegates all storage operations to a small "driver" object that implements this role. The bundled default is Dancer2::Plugin::ContentCache::Driver::DBIC, which stores cache entries via DBIx::Class. To use a different storage backend (Redis, a flat file, another ORM, whatever you like), write a class that consumes this role and point the driver configuration option at it.
A driver class is instantiated as:
$driver_class->new( plugin => $plugin, config => $plugin->config );
plugin is the running Dancer2::Plugin::ContentCache instance (handy if you need $plugin->app to reach other plugins), and config is the raw plugin configuration hashref, in case your driver needs its own settings.
REQUIRED METHODS
Any class that consumes this role must implement the following methods. The plugin never inspects storage internals itself; it only ever calls these five methods.
- has_aging_columns
-
Return a boolean indicating whether the backing store is capable of recording both a creation time and an expiry time for an entry. If
cache_agingis turned on in the plugin configuration and this method returns false,Dancer2::Plugin::ContentCachewillcroakwhen the application starts. - has_created_column
-
Return a boolean indicating whether the backing store can record a creation timestamp for an entry. This is independent of
cache_aging; a store may track "created" without tracking "expiry". - create_entry
-
$driver->create_entry( uuid => $uuid, data => $data_as_string, metadata => $metadata_as_json_string, created_dt => $created_dt, # a DateTime object, or undef expiry_dt => $expiry_dt, # a DateTime object, or undef );Persist a new, immutable cache entry.
dataandmetadataare already serialized to strings by the plugin; the driver need not know or care what they mean, only that they must come back unchanged fromfind_entry. - find_entry
-
my $entry = $driver->find_entry($uuid);Given a UUID, return a hashref with keys
uuid,data,metadata,created_dt, andexpiry_dt(the latter two areDateTimeobjects orundef, exactly as they were given tocreate_entry), or returnundefif no entry exists under that UUID. Note thatfind_entryis not responsible for enforcing expiry; the plugin itself decides whether an entry found here is still valid. - delete_expired
-
my $count = $driver->delete_expired;Delete all entries whose
expiry_dthas passed, and return the number of entries removed. If the driver does not support aging, this should simply return0.
SEE ALSO
AUTHOR
D Ruth Holloway <ruth@hiruthie.me>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by D Ruth Holloway.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.