| 1 | package LWP::UserAgent::Role::CHICaching::SimpleMungeResponse; | ||
| 2 | |||
| 3 | 3 | ▶ | use 5.006000; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use CHI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 3 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 3 | ▶ | use Types::Standard qw(Bool); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 3 | our $AUTHORITY = 'cpan:KJETILK'; | |
| 8 | 3 | our $VERSION = '0.04'; | |
| 9 | |||
| 10 | =pod | ||
| 11 | |||
| 12 | =encoding utf-8 | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | LWP::UserAgent::Role::CHICaching::SimpleMungeResponse - A role to manipulate the response when caching | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | See L<LWP::UserAgent::Role::CHICaching>. | ||
| 21 | |||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | When caching, it is sometimes useful to change the response, in | ||
| 26 | particular the body in some way for caching. In some cases, you might | ||
| 27 | not want to store the entire body, but compress it in some way, or | ||
| 28 | store the data in a different data structure than the serialized | ||
| 29 | version shared over the network. | ||
| 30 | |||
| 31 | The methods here are used to first manipulate the response before it | ||
| 32 | is sent to the cache, and then a cached response before it is returned | ||
| 33 | to the client. | ||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | =head2 Methods | ||
| 38 | |||
| 39 | =over | ||
| 40 | |||
| 41 | |||
| 42 | =item C<< cache_set($response, $expires_in) >> | ||
| 43 | |||
| 44 | A method that takes the L<HTTP::Response> from the client and an | ||
| 45 | expires time in seconds and set the actual cache. This role's | ||
| 46 | implementation stores the response as it is. | ||
| 47 | |||
| 48 | |||
| 49 | =item C<< finalize($cached) >> | ||
| 50 | |||
| 51 | A method that takes the cached entry as an argument, and will return a | ||
| 52 | L<HTTP::Response> to return to the client. This implementation returns | ||
| 53 | the response directly from the cache. | ||
| 54 | |||
| 55 | =back | ||
| 56 | |||
| 57 | =head1 TODO | ||
| 58 | |||
| 59 | The standard has a C<no-transform> directive that is relevant to this, | ||
| 60 | since roles such as this can be used to transform the response. This | ||
| 61 | needs to be dealt with. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | |||
| 66 | 2 | ▶ | sub finalize { |
|
Subroutine
finalize: called CC=1 SCAR=0.0
Pod
documented
| |||
| 67 | 2 | return $_[1]; | |
| 68 | } | ||
| 69 | |||
| 70 | 4 | ▶ | sub cache_set { |
|
Subroutine
cache_set: called CC=1 SCAR=0.0
Pod
documented
| |||
| 71 | 4 | my ($self, $res, $expires_in) = @_; | |
| 72 | 4 | return $self->cache->set($self->key, $res, { expires_in => $expires_in }); | |
| 73 | } | ||
| 74 | |||
| 75 | 3 | 1; | |
| 76 | |||
| 77 | |||
| 78 | __END__ | ||