| 1 | package LWP::UserAgent::CHICaching; | ||
| 2 | |||
| 3 | 3 | ▶ | use 5.006000; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 3 | our $AUTHORITY = 'cpan:KJETILK'; | |
| 6 | 3 | our $VERSION = '0.04'; | |
| 7 | |||
| 8 | 3 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 3 | extends 'LWP::UserAgent'; | |
| 11 | 3 | with 'LWP::UserAgent::Role::CHICaching', | |
| 12 | 'LWP::UserAgent::Role::CHICaching::SimpleKeyGen', | ||
| 13 | 'LWP::UserAgent::Role::CHICaching::SimpleMungeResponse'; | ||
| 14 | |||
| 15 | 3 | 1; | |
| 16 | |||
| 17 | |||
| 18 | =pod | ||
| 19 | |||
| 20 | =encoding utf-8 | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | LWP::UserAgent::CHICaching - LWP::UserAgent with caching based on CHI | ||
| 25 | |||
| 26 | =head1 SYNOPSIS | ||
| 27 | |||
| 28 | The usual way of using L<LWP::UserAgent>, really, just pass a C<cache> | ||
| 29 | parameter with a L<CHI> object to the constructor: | ||
| 30 | |||
| 31 | my $cache = CHI->new( driver => 'Memory', global => 1 ); | ||
| 32 | my $ua = LWP::UserAgent::CHICaching->new(cache => $cache); | ||
| 33 | my $res1 = $ua->get("http://localhost:3000/?query=DAHUT"); | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | This is YA caching user agent. When the client makes a request to the | ||
| 38 | server, sometimes the response should be cached, so that no actual | ||
| 39 | request has to be sent at all, or possibly just a request to validate | ||
| 40 | the cache. HTTP 1.1 defines how to do this. This class simply extends | ||
| 41 | L<LWP::UserAgent> with L<LWP::UserAgent::Role::CHICaching> (also in | ||
| 42 | this distribution) which is doing the real work to make it possible to | ||
| 43 | use the very flexible L<CHI> module to manage such a cache. | ||
| 44 | |||
| 45 | But why? Mainly because I wanted to use L<CHI> facilities, and partly | ||
| 46 | because I wanted to focus on HTTP 1.1 features. | ||
| 47 | |||
| 48 | =head1 TODO | ||
| 49 | |||
| 50 | This is an early release, but it supports RFC7234 quite well | ||
| 51 | already. Much work remains though. These are the things that I'd like | ||
| 52 | to do: | ||
| 53 | |||
| 54 | =over | ||
| 55 | |||
| 56 | =item * Enable smarter generation of keys, so that semantically | ||
| 57 | identical content can be cached efficiently even though they may have | ||
| 58 | different URIs. This can be done in a separate role with the current | ||
| 59 | code. | ||
| 60 | |||
| 61 | =item * Support all of L<RFC7234|http://tools.ietf.org/html/rfc7234> | ||
| 62 | and L<RFC7232|http://tools.ietf.org/html/rfc7232> | ||
| 63 | |||
| 64 | =back | ||
| 65 | |||
| 66 | =head1 AUTHOR | ||
| 67 | |||
| 68 | Kjetil Kjernsmo E<lt>kjetilk@cpan.orgE<gt>. | ||
| 69 | |||
| 70 | =head1 COPYRIGHT AND LICENCE | ||
| 71 | |||
| 72 | This software is copyright (c) 2015, 2016 by Kjetil Kjernsmo. | ||
| 73 | |||
| 74 | This is free software; you can redistribute it and/or modify it under | ||
| 75 | the same terms as the Perl 5 programming language system itself. | ||
| 76 | |||
| 77 | |||
| 78 | =head1 DISCLAIMER OF WARRANTIES | ||
| 79 | |||
| 80 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||
| 81 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||
| 82 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
| 83 | |||