Jakob Voß > RDF-Flow-0.178 > RDF::Flow::Cached

Download:
RDF-Flow-0.178.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.178   Source  

NAME ^

RDF::Flow::Cached - Caches a source

VERSION ^

version 0.178

SYNOPSIS ^

  use CHI;                          # create a cache, for instance with CHI
  my $cache = CHI->new( ... );

  use RDF::Flow::Cached;        # plug cache in front of an existing source
  my $cached_source = RDF::Flow::Cached->new( $source, $cache );

  my $cached_source = $source->cached( $cache );       # alternative syntax

  use RDF::Flow qw(cached);
  my $cached_source = cached( $source, $cache );       # alternative syntax

  # guarded cache
  my $cached = cached( $source, $cache, guard => $quick_cache );

DESCRIPTION ^

Plugs a cache in front of a RDF::Flow::Source. Actually, this module does not implement a cache. Instead you must provide an object that provides at least two methods to get and set an object based on a key. See CHI, Cache, and Cache::Cache for existing cache modules.

The request URI in rdflow.uri is used as caching key. rdflow.cached is set if the response has been retrieved from the cache. rdflow.timestamp reflects the timestamp of the original source, so you get the timestamp of the cached response when it was first retrieved and stored in the cache.

METHODS ^

guard

You can get and/or set a guarding cache with this accessor.

CONFIGURATION ^

You can also use a cached source to guard against unreliable sources, which sometimes just return nothing, for instance because of a failure. To do so, use a quickly expiring second cache as "guard". This guard is not used to actually store data, but only to save the information that some data (at least one triple) has been retrieved from the source. The source is not queried again, until the guard expires. If, afterwards, the source returns no data, data is returned from the cache instead. A possible setting is to use a non-expiring cache as backend, guared by a another cache;

  use CHI;
  my $store = CHI->new( driver => 'File', root_dir => '/path/to/root' );
  my $guard = CHI->new( driver => 'Memory', global => 1 );

  my $cached = cached( $source, $store, guard => $guard );

However be sure not to use the same cache (root_dir, global...) for caching different sources.

SEE ALSO ^

Plack::Middleware::Cached implements almost the same mechanism for caching general PSGI applications.

AUTHOR ^

Jakob Voß <voss@gbv.de>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2011 by Jakob Voß.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: