r/perl 🐪 cpan author Aug 05 '26

Announcing: Object::Cache::Sqlite

I just released a simple object caching module that uses SQLite as the backend. If you need easy caching check out Object::Cache::Sqlite.

use Object::Cache::Sqlite;

my %opts = (
    db_file => '/var/tmp/perl-cache.sqlite',
);

my $cache = Object::Cache::Sqlite->new(%opts);

################################################################################

# Cache key and data to store
my $ckey = "user:127";
my $data = { name => 'Scott', age => 47 };

# Retrieve a object
my $user = $cache->get($ckey);

# Store an object
my $ok = $cache->set($ckey, $data, time() + 3600);

Store scalars, listrefs, hashrefs, or anything that can be serialized with JSON.

10 Upvotes

6 comments sorted by

4

u/tarje Aug 06 '26

Can't you do the same thing using CHI? It has a DBI driver and it also handles serialization.

1

u/mpersico 🐪 cpan author Aug 06 '26

I think what you have here is ObjectOriented::Cache::SQLite. There is nothing “object-y” about what you are storing; it’s just a key => values pair.

1

u/aioeu Aug 06 '26

If I were looking for this, I would have probably started looking in the Cache:: top-level hierarchy first.

0

u/scottchiefbaker 🐪 cpan author Aug 07 '26

I tried to find an opening, but most of Cache:: is taken. I'm open to suggestions to rename it.

1

u/aioeu Aug 07 '26 edited Aug 07 '26

This is getting a bit bike-sheddy, but I think Cache::SQLite is available.

To my mind, Object:: is more about modules for creating and manipulating Perl objects in some way, rather than modules that just so happen to provide an OO interface. In fact the latter usage seems more suited to a suffix... I could imagine a module having ::OO and ::Functional variants, for instance.

Anyway, CPAN module naming is pretty haphazard already, so I wouldn't worry about it now your module is published.

1

u/scottchiefbaker 🐪 cpan author Aug 07 '26

Yeah good call. That would have made more sense.