Masatoshi Mizuno > Egg-Plugin-Cache-UA > Egg::Plugin::Cache::UA



Annotate this POD

View/Report Bugs
Module Version: 1.00   Source  


Egg::Plugin::Cache::UA - The result of the WEB request is cached.


  package MyApp;
  use Egg qw/Cache::UA/;

  package MyApp::Dispatch;
    cache=> {
      google => sub {
        my($e)= @_;
      brainer=> sub {
        my($e)= @_;


This module caches and recycles the request result of Egg::Plugin::LWP.

Especially, I think that it is effective in the contents match system advertisement etc. 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.

It is necessary to setup Egg::Model::Cache to use it, and to set the label name to acquire the model to 'cache_name' of the configuration.

This module has succeeded to Egg::Plugin::LWP.


The configuration is set by 'plugin_cache_ua'.

  package MyApp;
    plugin_cache_ua => {
      cache_name         => 'cache_model_name',
      allow_hosts        => [qw/ /],
      content_type       => 'text/html',
      content_type_error => 'text/html',
      cache_expires      => 60* 60,
      expires            => '+1d',
      last_modified      => '+1d',


The host name that permits the use of cashe is set with ARRAY.

It is necessary to set this.

  allow_hosts => [qw/ /],

When the regular expression is set, the access is not accepted because each value is put on quotemeta.

When it is not possible to acquire it, processing is continued disregarding this setting though it checks with HTTP_REFERER of the environment variable because the thing that cannot be acquired under the influences of the proxy and the security software, etc. can break out, too.


Default of sent contents type.

This setting is substitution when the contents type is not obtained because of the WEB request.

'text/html' is used if it unsets it.

  content_type=> 'text/javascript',


Contents type used when data is not obtained by some errors' occurring by WEB request.

Default is 'text/html'.


Model name of cashe used.

The model name to acquire the cashe object set up with Egg::Model::Cache is set.

There is no default. Please set it.


It is a value passed to the third argument of 'set' method of cashe.

This is a setting that assumes the use of Cache::Memcached.

  cache_expires=> 60* 60,  # It is effective for one hour.

It is not necessary to set it usually.

Validity term is done depending on the cashe model used.

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',


It is request a method when WEB is requested.

Default is 'GET'.

I think that you should specify this when you are putting necessary in 'get' method as undefined usually.

  $e->cache_ua->get( 'http://.....' => { request_method=> 'POST' } );



The Egg::Plugin::Cache::UA::handler object is returned.

 my $cache_ua= $e->cache_ua;


get ( [URL], [OPTION] )

The request is sent to URL.

The content is returned if becoming a hit to cashe.

OPTION overwrites the default.

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 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.

The content of the returned HASH reference is as follows.


Succeeding in the request is true.


There is a status line obtained because of the response.


There is a contents type obtained because of the response.

Instead, the default of the setting enters when the contents type is not obtained.


There is a content of contents obtained because of the response.


One the respondent error message enters when is_success is false.


When not becoming a hit to cashe, it becomes true.

output ( [URL], [OPTION] )

Content is set directly to Egg::Response based on information obtained by the get method.

The response header set here is as follows.


When no_hit is only false, it is set. In a word, the thing that becomes a hit to cashe is shown.

expires or last_modified

It is set based on the setting.


The obtained status line is set.


The obtained contents type is set.

delete ( [URL] )

The data of URL is deleted from cashe.


cache ([LABEL_NAME])

The cashe object set to 'cache_name' is returned usually.

When LABEL_NAME is specified, an arbitrary model object is returned.

 my $cache= $e->cache_ua->cache('cache_label');


Egg::Release, Egg::Response, Egg::Plugin::LWP, Egg::Model::Cache,


Masatoshi Mizuno <>


Copyright (C) 2008 by Bee Flag, Corp. <>, 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.

syntax highlighting: