Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Persistant data with Mason

by bpphillips (Friar)
on Feb 11, 2005 at 14:34 UTC ( [id://430221]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Persistant data with Mason

if you're needing access to this data from with Mason, you can use Mason's built in data caching. First you create a component file to encapsulate the data you want to share across requests and processes (i.e. "_getSharedData").
# mason component _getSharedData my $value = $m->cache->get("key"); return $value if(defined($value)); # compute $value here since it hasn't been stored yet $value = $$; $m->cache->set(key=>$value); return $value
Then you can call that component anytime you want to retrieve it.
my $value = $m->comp('/_getSharedData');
Note that Mason's cache, by default, is stored on disk but you can use any Cache::Cache sub-class that you want (Cache::SharedMemoryCache would allow you to share the data across processes without writing it to disk).
$m->cache(cache_class => 'SharedMemoryCache')->set(key=>$value); $value = $m->cache(cache_class => 'SharedMemoryCache')->get("key");
Also, $m->cache->get("key") is scoped to the component you are calling it from (so don't expect to be able to access the same data from another component without calling _getSharedData

For more info on Mason caching, see the HTML::Mason::Devel docs.

HTH - Brian

Replies are listed 'Best First'.
Re^2: Persistant data with Mason
by cowboy (Friar) on Feb 11, 2005 at 16:36 UTC
    I believe Cache::Cache recommends using Cache::FileCache rather than Cache::SharedMemoryCache. Other than that, I agree, a cache is probably the easiest way to go. Cache::FileCache on a tmpfs or other sort of ram disk, is quite quick. Alternatively, as others have suggested, a light weight DB backend also makes sharing easy.
Re: Persistant data with Mason
by crenz (Priest) on Feb 11, 2005 at 19:23 UTC
    Thanks, this is actually a very good suggestion. Using the environment won't work, as I'll be accessing the Perl interpreter's %ENV, not Apache's. I might dabble with Shared Memory directly some time, but for now, I think I'll just use Mason's caching capabilities to avoid reinventing the wheel...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://430221]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.