Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Caching a hash?

by pboin (Deacon)
on Mar 09, 2006 at 14:36 UTC ( #535479=note: print w/replies, xml ) Need Help??

in reply to Caching a hash?

You may also want to read up on Memoize. I saw it presented lately, and was pretty impressed w/ what it does. It might fit into your problem in a way you haven't thought of yet. It's trivially easy to implement, too. Here's the summary:

'Memoizing' a function makes it faster by trading space for time. It does this by caching the return values of the function in a table. If you call the function again with the same arguments, memoize jumps in and gives you the value out of the table, instead of letting the function compute the value all over again.

Oh, and as to the module problem, if you have write access for the source that you've written, there's no reason why you can't lay down code that comes from CPAN too. After all, it's (usually) just Perl code, there's nothing magic about it.

Replies are listed 'Best First'.
Re^2: Caching a hash?
by guice (Scribe) on Mar 10, 2006 at 16:42 UTC

    I'll check that out. I've gotten in the habit of using variable caching for methods I might repeatably call (ie, db method to return the db object) and use did basic isset() checks; setting the value if false and returning the variable.

    That can be useful for methods were I have a rather large return array and want to free up some memory instead of keeping the values stored in a local variable (pretty much what I'm needing and more). Thanks!

    And the module part, generally this is true although some stronger modules (especially ones that start playing around with memory and system level stuff) requires compiled code. So I just wanted to make sure I cleared that restriction before I get a slew of mem_cache type modules suggested

    -- philip
    We put the 'K' in kwality!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://535479]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2021-07-26 01:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found