ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/URL/URLcache.pm
(Generate patch)

Comparing COMP/SCRAM/src/URL/URLcache.pm (file contents):
Revision 1.1 by williamc, Mon Oct 25 06:35:32 1999 UTC vs.
Revision 1.4 by williamc, Fri Nov 12 17:38:27 1999 UTC

# Line 5 | Line 5
5   #
6   # Description
7   # -----------
8 < # Simple url->file lookup
8 > # Simple url->file lookup (persistent)
9   #
10   # Interface
11   # ---------
12 < # new(cachedir)         : A new URLcache object
12 > # new(cachedir)         : A new URLcache object in a given directory
13   # store(url,file)       : store a url/file combination
14 < # file(url)             : retunr the file for a given url or "" if not there
14 > # file(url)             : return the file for a given url
15   # delete(url)           : remove from cache url
16   # clear()               : clear cache
17 + # filestore()           : Return the directory to download files to
18 + # filename(url)         : return a unique file/dir in cache for the given url
19 + # updatenumber(int)     : return an integer number changed with each store
20  
21   package URL::URLcache;
22   require 5.004;
23 < use Utilities::HashDB;
24 <
22 < sub new {
23 <        my $class=shift;
24 <        $self={};
25 <        bless $self, $class;
26 <        $self->init(@_);
27 <        return $self;
28 < }
29 <
30 < sub init {
31 <        my $self=shift;
32 <        $self->{cachedir}=shift;
33 <
34 <        $self->{cacheindex}=$self->{cachedir}."/index.db";
35 <        $self->{urlDB}=Utilities::HashDB->new();
36 <        if ( -f $self->{cacheindex} ) {
37 <          $self->{urlDB}->restore($self->{cacheindex});
38 <        }
39 <        else {
40 <          AddDir::adddir($self->{cachedir});
41 <        }
42 < }
43 <
44 < sub file {
45 <        my $self=shift;
46 <        my $url=shift;
47 <
48 <        my $found;
49 <        ($found)=$self->{urlDB}->getdata($url);
50 <        return ( ($found eq "")?"":$found);
51 < }
52 <
53 < sub delete {
54 <        my $self=shift;
55 <        my $url=shift;
56 <        $self->{urlDB}->deletedata($url);
57 <        $self->{urlDB}->store($self->{cacheindex});
58 < }
59 <
60 < sub store {
61 <        my $self=shift;
62 <        my $url=shift;
63 <        my $file=shift;
64 <
65 <        $self->{urlDB}->deletedata($url);
66 <        $self->{urlDB}->setdata($file,$url);
67 <        $self->{urlDB}->store($self->{cacheindex});
68 < }
69 <
70 < sub clear {
71 <        my $self=shift;
72 <        unlink $self->{cacheindex};
73 < }
23 > use Utilities::IndexedFileStore;
24 > @ISA=qw(Utilities::IndexedFileStore)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines