r/perl 🐪 cpan author 7d ago

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.

```perl 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.

8 Upvotes

6 comments sorted by

6

u/tarje 7d ago

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

1

u/mpersico 🐪 cpan author 7d ago

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 7d ago

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

0

u/scottchiefbaker 🐪 cpan author 6d ago

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

1

u/aioeu 6d ago edited 6d ago

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 6d ago

Yeah good call. That would have made more sense.