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