NAME
Egg::Plugin::Cache::UA - The result of LWP is cached for Egg::Plugin.
SYNOPSIS
use Egg qw/Cache::UA/;
.......
.....
__PACKAGE__->dispatch_map(
cache=> {
google => sub {
my($e)= @_;
$e->cache_ua->output('http://xxx.googlesyndication.com/pagead/show_ads.js');
},
brainer=> sub {
my($e)= @_;
$e->cache_ua->output('http://xxx.brainer.jp/ad.js');
},
},
);
DESCRIPTION
This module cache and recycles the request result of Egg::Plugin::LWP.
Especially, I think that it is effective in an advertising usage of the contents match system of the type that returns the JAVA script.
It becomes difficult to receive the influence of the response speed of advertisement ASP server by the action of cashe.
Because this module has succeeded to Egg::Plugin::LWP and Egg::Plugin::Cache, it is not necessary to read separately.
CONFIGURATION
Please go in Configuration of this module with the key 'plugin_cache_ua'.
* It is necessary to setup Egg::Plugin::LWP and Egg::Plugin::Cache.
* Especially, the setting of User-Agent recommends the thing customized without fail in Egg::Plugin::LWP.
allow_hosts
Please set the host name that permits the use of cashe with ARRAY.
* It is necessary to set it.
allow_hosts => [qw/ www.domain.com domain.com domain.net /],
* Because each value is put on 'quotemeta', the regular expression is not effective well. Please enumerate the host name usually.
* Under the influences of the proxy and the security software, etc. though it checks with 'HTTP_REFERER' When it is not possible to acquire it, it is not refused because the thing that cannot be acquired can break out, too.
content_type
Default of sent contents type.
* Please set it if you call the output method.
'text/html' is used if it unsets it.
content_type=> 'text/javascript',
content_type_error
Contents type for error screen when some errors occur.
Default is 'text/html';
cache_name
Cashe name set to Egg::Plugin::Cache.
There is no default and set it, please.
cache_name => 'FileCache',
cache_expires
When "Cache::Memcached " is used with Egg::Plugin::Cache, the validity term of cashe is set by this setting.
* It is not necessary usually.
cache_expires=> 60* 60, # one hour.
expires or last_modified
The response header to press the cashe of the browser side is set.
* It specifies it by the form used by CGI module.
expires => '+1d',
last_modified => '+1d',
METHODS
cache_ua
The Egg::Plugin::Cache::UA::handler object is returned.
my $cache_ua= $e->cache_ua;
HADLER METHODS
It is a method of the object returned by $e->cache_ua.
get ( [URL], [OPTION] )
The GET request is sent to URL. * It is not possible to request it to URL that the methods other than GET are demanded.
The content is returned if becoming a hit to cashe.
The HASH reference returns to the return value without fail.
my $res= $e->cache_ua->get('http://domainname/');
if ($res->{is_success}) {
$e->stash->{request_content}= \$res->{content};
} else {
$e->finished($res->{status} || 500);
}
The content of HASH is as follows.
is_success
Succeeding in the request is true.
status
There is a status line obtained because of the response.
content_type
There is a contents type obtained because of the response.
* Instead, the default of the setting enters when the contents type is not obtained.
content
There is a content of contents obtained because of the response.
error
One the respondent error message enters when is_success is false.
no_hit
When not becoming a hit to cashe, it becomes true.
output ( [URL], [OPTION] )
Egg::Response is set directly based on information obtained by the get method.
The response header set here is as follows.
X-CACHE-UA
When no_hit is only false, it is set. It will be said that it became a hit to cashe in a word.
expires or last_modified
It is set based on the setting.
status
If the status line is obtained, it is set.
content_type
The obtained contents type is set.
The content of content is set in $e->response->body. When content is not obtained by the error's occurring by the request, the content of error is set.
* Because $e->response->body is defined, the processing of view comes to be passed by the operation of Egg.
delete ( [URL] )
The data of URL is deleted from cashe.
$e->delete('http://domainname/');
Alias is 'remove'.
cache
The cashe object set to 'cache_name' is returned.
my $cache= $e->cache_ua->cache;
SEE ALSO
Egg::Plugin::LWP, Egg::Plugin::Cache, Egg::Response, Egg::Release,
AUTHOR
Masatoshi Mizuno <lushe@cpan.org>
COPYRIGHT
Copyright (C) 2007 by Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 102:
L<> starts or ends with whitespace