Apache-Storage
view release on metacpan or search on metacpan
my $r = Apache->request;
my $cfg = Apache::ModuleConfig->get($r);
if (ref($key) eq 'HASH'){
for(keys %$key) {
$cfg->{'longterm'}{$_} = $key->{$_};
}
} else {
$cfg->{'longterm'}{$key} = $value;
}
}
sub get_storage {
my($key) = @_;
my $r = Apache->request;
my $cfg = Apache::ModuleConfig->get($r);
if (ref($key) eq 'ARRAY'){
my @array;
for(@$key) {
push @array, $cfg->{'longterm'}{$_};
}
return \@array;
} else {
return $cfg->{'longterm'}{$key};
}
}
sub get_storage_dump {
my $r = Apache->request;
my $cfg = Apache::ModuleConfig->get($r);
return $cfg->{'longterm'};
}
# Believe it or not, this is hear for a reason
sub DESTROY {
}
1;
__END__
=head1 NAME
Apache::Storage - Storing data in Apache.
=head1 SYNOPSIS
use Apache::Storage;
=head1 DESCRIPTION
Ever wanted to store information in Apache so
the additional requests could gain access to it?
For example, you create an object which is fairly
expensive and you don't want to have to
recreate each time, or say you just have some
information you are storing in a reference that
you want requests that follow you to see.
This module is for you.
It has three functions described below. They allow
you to store and retrieve information from the
Apache process. The functions are fairly simple
and should make it pretty easy for you to do so
without to much hassle.
All of this works with subrequests, so unlike
pnotes, you don't need to worry about loosing
data if your request is subrequested by an outside
Apache module.
You can also use the ApacheStorage directive inside
of Apache to prime data into the Apache::Storage.
=head2 FUNCTIONS
Note
Keep in mind that data is only stored on the Apache
process itself. Different child processes all
have their own storage. Don't assume you will
get the same Apache child process when reconnecting.
Make sure you put a "PerlModule Apache::Storage" in
your httpd.conf file. Apache make core if you do
not do this.
=over 4
=item set_storage
Set functions can be called in two ways. They can be
called with a key and a reference. The reference will
then be available by calling it through a get function.
You can also pass in hash reference. The contents of
this hash will be mapped into storage based on it
original key pair. Nothing is returned by either of
these functions
=item get_storage
Get functions can be calling in two ways. They can either
be called with a single key, where they will return a
single hash
=item get_storage_dump
This gives you a hash of the entire contents of
what is being stored currently.
=back
=head2 Apache Directives
( run in 1.465 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )