Commit | Line | Data |
9038e305 |
1 | package Memoize::ExpireTest; |
a0cb3900 |
2 | |
9038e305 |
3 | =head1 NAME |
a0cb3900 |
4 | |
9038e305 |
5 | Memoize::ExpireTest - test for Memoize expiration semantics |
6 | |
7 | =head1 DESCRIPTION |
8 | |
9 | This is just for testing expiration semantics. It's not actually a |
10 | very good example of how to write an expiration module. |
11 | |
12 | If you are looking for an example, I recommend that you look at the |
13 | simple example in the Memoize::Expire documentation, or at the code |
14 | for Memoize::Expire itself. |
15 | |
16 | If you have questions, I will be happy to answer them if you send them |
17 | to mjd-perl/memoize+@plover.com. |
18 | |
19 | =cut |
a0cb3900 |
20 | |
21 | my %cache; |
22 | |
23 | sub TIEHASH { |
24 | my ($pack) = @_; |
25 | bless \%cache => $pack; |
26 | } |
27 | |
28 | sub EXISTS { |
29 | my ($cache, $key) = @_; |
30 | exists $cache->{$key} ? 1 : 0; |
31 | } |
32 | |
33 | sub FETCH { |
34 | my ($cache, $key) = @_; |
35 | $cache->{$key}; |
36 | } |
37 | |
38 | sub STORE { |
39 | my ($cache, $key, $val) = @_; |
40 | $cache->{$key} = $val; |
41 | } |
42 | |
43 | sub expire { |
44 | my ($key) = @_; |
45 | delete $cache{$key}; |
46 | } |
47 | |
48 | 1; |