23 Feb 2012 13:41:10 UTC
- Distribution: RDF-Flow
- Module version: 0.178
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (261 / 202 / 16)
- KwaliteeBus factor: 1
- 94.00% Coverage
- License: perl_5
- Perl: v5.10.0
- Activity24 month
- Download (23.12KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionVOJ Jakob Voßand 1 contributors
- Jakob Voß
RDF::Flow::Cached - Caches a source
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 );
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.uriis used as caching key.
rdflow.cachedis set if the response has been retrieved from the cache.
rdflow.timestampreflects 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.
You can get and/or set a guarding cache with this accessor.
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 (
global...) for caching different sources.
Plack::Middleware::Cached implements almost the same mechanism for caching general PSGI applications.
Jakob Voß <email@example.com>
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.