ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/URL/URLcache.pm
Revision: 1.1
Committed: Mon Oct 25 06:35:32 1999 UTC (25 years, 6 months ago) by williamc
Content type: text/plain
Branch: MAIN
Log Message:
Simple URL lookup mechanism

File Contents

# User Rev Content
1 williamc 1.1 #
2     # URLcache.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # Simple url->file lookup
9     #
10     # Interface
11     # ---------
12     # new(cachedir) : A new URLcache object
13     # store(url,file) : store a url/file combination
14     # file(url) : retunr the file for a given url or "" if not there
15     # delete(url) : remove from cache url
16     # clear() : clear cache
17    
18     package URL::URLcache;
19     require 5.004;
20     use Utilities::HashDB;
21    
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     }