~ubuntu-branches/ubuntu/feisty/pyblosxom/feisty

« back to all changes in this revision

Viewing changes to libs/cache/base.py

  • Committer: Bazaar Package Importer
  • Author(s): Tollef Fog Heen
  • Date: 2005-04-06 18:56:44 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050406185644-t4dg3gqw55bdfu3z
Tags: 1.2-1
* New upstream release (closes: #291726)
  - no contributed plugins any more.  License issues and upstream
    splitting it out of the upstream tarball.
  - No more xmlrpc.py (closes: #227080, #229342)
  - Now actually uses ignore_directories correctly (closes: #271655)
  - Corrected use of hex constants (closes: #274830)
  - Uses $pyblosxom_version in default renderer (closes: #282603)
  - No longer has version number in default config file (closes: #231621)

* Update new upstream URL in welcome.txt
* Update license to the MIT license.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 expandtab
2
 
"""
3
 
A basic driver, used by default in pyblosxom, does not do anything at all
4
 
"""
5
 
class BlosxomCacheBase:
6
 
    """
7
 
    Base Class for Caching stories in pyblosxom.
8
 
 
9
 
    A cache is a disposable piece of data that gets updated when an entry is in a
10
 
    fresh state.
11
 
 
12
 
    Drivers are to subclass this object, overriding methods defined in this class.
13
 
    If there is an error in creating cache data, be as quite as possible, document
14
 
    how a user could check whether his cache works.
15
 
 
16
 
    Driver should expect empty caches and should attempt to create them from
17
 
    scratch.
18
 
 
19
 
    @cvar _config: String containing config on where to store the cache. The Value
20
 
        of config is derived from C{py['cacheConfig']} in L{config}.
21
 
    @type _config: string
22
 
    """
23
 
    def __init__(self, config):
24
 
        """
25
 
        Constructor - setup and load up the cache
26
 
 
27
 
        @param config: String containing config on where to store the cache
28
 
        @type config: string
29
 
        """
30
 
        self._config = config
31
 
 
32
 
 
33
 
    def load(self, entryid):
34
 
        """
35
 
        Try to load up the cache with entryid (a unique key for the entry)
36
 
 
37
 
        @param entryid: The key identifier for your cache
38
 
        @type entryid: string
39
 
        """
40
 
        self._entryid = entryid # The filename of the entry
41
 
        self._entrydata = {}    # The data of the entry
42
 
 
43
 
 
44
 
    def getEntry(self):
45
 
        """
46
 
        Gets the data from the cache, returns a dict or an empty dict.
47
 
        """
48
 
        return self._entrydata
49
 
 
50
 
 
51
 
    def isCached(self):
52
 
        """
53
 
        Returns 0 or 1 based on whether there is cached data, returns 0 is
54
 
        cache data is stale
55
 
 
56
 
        @returns: 0 or 1 based on cache
57
 
        @rtype: boolean
58
 
        """
59
 
        return 0
60
 
 
61
 
 
62
 
    def saveEntry(self, entrydata):
63
 
        """
64
 
        Store entrydata in cache
65
 
 
66
 
        @param entrydata: The payload, usually a dict
67
 
        @type entrydata: dict
68
 
        """
69
 
        pass
70
 
 
71
 
 
72
 
    def rmEntry(self):
73
 
        """
74
 
        Remove cache entry: This is not used by pyblosxom, but used by
75
 
        utilities
76
 
        """
77
 
        pass
78
 
 
79
 
 
80
 
    def close(self):
81
 
        """
82
 
        Close your cache if necessary.
83
 
        """
84
 
        pass
85
 
 
86
 
 
87
 
    def __getitem__(self, key):
88
 
        """
89
 
        Convenience function to make this class look like a dict
90
 
        """
91
 
        self.load(key)
92
 
        if not self.has_key(key):
93
 
            raise KeyError
94
 
        return self.getEntry()
95
 
 
96
 
 
97
 
    def __setitem__(self, key, value):
98
 
        """
99
 
        Synonymous to L{saveEntry}
100
 
        """
101
 
        self.load(key)
102
 
        self.saveEntry(value)
103
 
 
104
 
 
105
 
    def __delitem__(self, key):
106
 
        self.load(key)
107
 
        self.rmEntry()
108
 
 
109
 
 
110
 
    def has_key(self, key):
111
 
        self.load(key)
112
 
        return self.isCached()
113
 
 
114
 
 
115
 
    def keys(self):
116
 
        """
117
 
        List out a list of keys for the cache, to be overridden by a subclass
118
 
        if a full dict interface is required.
119
 
        """
120
 
        return []
121
 
 
122
 
 
123
 
    def get(self, key, default=None):
124
 
        try:
125
 
            return self.__getitem__(key)
126
 
        except KeyError:
127
 
            return default
128
 
 
129
 
 
130
 
class BlosxomCache(BlosxomCacheBase):
131
 
    """
132
 
    A Null cache
133
 
    """
134
 
    pass