| 1 |
|
|---|
| 2 | package Memoize::Expire;
|
|---|
| 3 | # require 5.00556;
|
|---|
| 4 | use Carp;
|
|---|
| 5 | $DEBUG = 0;
|
|---|
| 6 | $VERSION = '1.00';
|
|---|
| 7 |
|
|---|
| 8 | # This package will implement expiration by prepending a fixed-length header
|
|---|
| 9 | # to the font of the cached data. The format of the header will be:
|
|---|
| 10 | # (4-byte number of last-access-time) (For LRU when I implement it)
|
|---|
| 11 | # (4-byte expiration time: unsigned seconds-since-unix-epoch)
|
|---|
| 12 | # (2-byte number-of-uses-before-expire)
|
|---|
| 13 |
|
|---|
| 14 | sub _header_fmt () { "N N n" }
|
|---|
| 15 | sub _header_size () { length(_header_fmt) }
|
|---|
| 16 |
|
|---|
| 17 | # Usage: memoize func
|
|---|
| 18 | # TIE => [Memoize::Expire, LIFETIME => sec, NUM_USES => n,
|
|---|
| 19 | # TIE => [...] ]
|
|---|
| 20 |
|
|---|
| 21 | BEGIN {
|
|---|
| 22 | eval {require Time::HiRes};
|
|---|
| 23 | unless ($@) {
|
|---|
| 24 | Time::HiRes->import('time');
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
|
|---|