manually expire an element in Memoize (also on comp.lang.perl.misc)

manually expire an element in Memoize (also on comp.lang.perl.misc)

am 14.02.2007 23:52:04 von Daniel McBrearty

hi all

I like and use MJ Dominus' excellent Memoize module to cache some
stuff in my app that hits a db rather hard. It's very simple :

use Memoize;

memoize('my_accessor');

sub my_accessor {
my ($key1, $key2) = @_;
# look up $key1, $key2 in the db and return a scalar

}

and the function is magically cached without the need to do any more.

Now what I'd like is, in another function, to manually invalidate (or
delete) certain cached values at runtime (most likely because I
changed the value in the db).

How can I do this? I looked at the docs and source for
Memoize::Expire, but it's not too clear to me right now. Obviously,
I'd like the simplest possible solution ...

thanks

Daniel

(apologies for the cross post to comp.lang.perl.misc - this would have
been a better choice of group from the off ... )

Re: manually expire an element in Memoize (also on comp.lang.perl.misc)

am 15.02.2007 19:58:45 von javiermm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

danielmcbrearty@gmail.com escribió:
On 14 Feb 2007 14:52:04 -0800, danielmcbrearty@gmail.com wrote:
> I like and use MJ Dominus' excellent Memoize module to cache some
> stuff in my app that hits a db rather hard. It's very simple :
> [...]
> Now what I'd like is, in another function, to manually invalidate (or
> delete) certain cached values at runtime (most likely because I
> changed the value in the db).
>
> How can I do this?

If you read Memoize doc, you can see HASH option. You can set/get hash
where the memoize info is. You only need clear key of data you want
invalidate.

javier m mora.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFF1KzYpRHCj3lPPYMRAvi9AJ9TcgfxzUb9UaQ7GU5ci896BQGk6gCg miMD
PCZI9XNJyG6f0fbZehSJCXM=
=cV4d
-----END PGP SIGNATURE-----