~cjwatson/storm/py39

« back to all changes in this revision

Viewing changes to storm/cache.py

  • Committer: Colin Watson
  • Date: 2020-05-26 12:26:41 UTC
  • mfrom: (554.1.3 docstring-syntax)
  • Revision ID: cjwatson@canonical.com-20200526122641-591kmbjqf24em97w
Improve various docstrings, mainly fixing reST/epytext syntax. [r=ilasc,doismellburning]

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    This prevents recently used objects from being deallocated by Python
12
12
    even if the user isn't holding any strong references to it.  It does
13
13
    that by holding strong references to the objects referenced by the
14
 
    last C{N} C{obj_info}s added to it (where C{N} is the cache size).
 
14
    last C{N} C{obj_info}\ s added to it (where C{N} is the cache size).
15
15
    """
16
16
 
17
17
    def __init__(self, size=1000):
54
54
    def set_size(self, size):
55
55
        """Set the maximum number of objects that may be held in this cache.
56
56
 
57
 
        If the size is reduced, older C{obj_info}s may be dropped from
 
57
        If the size is reduced, older C{obj_info}\ s may be dropped from
58
58
        the cache to respect the new size.
59
59
        """
60
60
        if size == 0:
66
66
        self._size = size
67
67
 
68
68
    def get_cached(self):
69
 
        """Return an ordered list of the currently cached C{obj_info}s.
 
69
        """Return an ordered list of the currently cached C{obj_info}\ s.
70
70
 
71
71
        The most recently added objects come first in the list.
72
72
        """
103
103
        self._old_cache = {}
104
104
 
105
105
    def clear(self):
106
 
        """See `storm.store.Cache.clear`.
 
106
        """See L{Cache.clear}.
107
107
 
108
108
        Clears both the primary and the secondary caches.
109
109
        """
125
125
        self._new_cache.clear()
126
126
 
127
127
    def add(self, obj_info):
128
 
        """See `storm.store.Cache.add`."""
 
128
        """See L{Cache.add}."""
129
129
        if self._size != 0 and obj_info not in self._new_cache:
130
130
            if len(self._new_cache) >= self._size:
131
131
                self._bump_generation()
132
132
            self._new_cache[obj_info] = obj_info.get_obj()
133
133
 
134
134
    def remove(self, obj_info):
135
 
        """See `storm.store.Cache.remove`."""
 
135
        """See L{Cache.remove}."""
136
136
        in_new_cache = self._new_cache.pop(obj_info, None) is not None
137
137
        in_old_cache = self._old_cache.pop(obj_info, None) is not None
138
138
        return in_new_cache or in_old_cache
139
139
 
140
140
    def set_size(self, size):
141
 
        """See `storm.store.Cache.set_size`.
 
141
        """See L{Cache.set_size}.
142
142
 
143
143
        After calling this, the cache may still contain more than `size`
144
144
        objects, but no more than twice that number.
152
152
        self._old_cache.clear()
153
153
 
154
154
    def get_cached(self):
155
 
        """See `storm.store.Cache.get_cached`.
 
155
        """See L{Cache.get_cached}.
156
156
 
157
157
        The result is a loosely-ordered list.  Any object in the primary
158
158
        generation comes before any object that is only in the secondary