[Dbix-class] Caching total_entires in the Pager -- how can build a good cache key?

Bill Moseley moseley at hank.org
Thu Aug 8 18:51:47 GMT 2013

I have a REST app that returns collections a page at a time.   So, part of
that response is the Data::Page object.

There is some overhead with fetching the total_entires each time I query
for the next page of results, and in my case it doesn't change frequently.
  So, I'm thinking about caching.

For example:

my $pager =3D $rs->pager;

if ( my $count =3D $cache->get( $key ) ) {
    $pager->total_entires( $count );
else {
    $cache->set( $key, $pager->total_entries, $timeout_seconds );

That is, populate total_entries from cache if I have it.

The problem is what to use for the cache key.   This seems to work, but
looks rather ugly.  Is there a better way?  Mostly copied from the pager()

my %attrs =3D %{$rs->{attrs}};
delete $attrs{$_} for qw/rows offset page pager/;

my $trs =3D (ref $rs)->new($rs->result_source, \%attrs)->count_rs;
my ( $sql, @bind )  =3D @{${$trs->as_query}};

my $key =3D join ':', $sql, grep { !ref }  map { @{$_} } @bind;

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130808/e62=

More information about the DBIx-Class mailing list