Commit 732f3ec1 authored by Tres Seaver's avatar Tres Seaver

Merge from 'tseaver-python_picklecache-2' branch:

```---------------------------------------------------------------------
r122975 | tseaver | 2011-09-27 13:31:54 -0400 (Tue, 27 Sep 2011) | 1 line

Move to match order defined in IPickleCache.
```

---------------------------------------------------------------------
r122974 | tseaver | 2011-09-27 13:31:06 -0400 (Tue, 27 Sep 2011) | 1 line

Tolerate being handed irrelevant arguments.
------------------------------------------------------------------------
r122973 | tseaver | 2011-09-27 13:31:05 -0400 (Tue, 27 Sep 2011) | 1 line

Enable 'Timestamp' fallback to 'timestamp' when extension unavailable.
------------------------------------------------------------------------
r122972 | tseaver | 2011-09-27 13:31:04 -0400 (Tue, 27 Sep 2011) | 3 lines

Don't raise KeyError for OID collision w/ same value object.

Also, implement stub of 'update_object_size_estimation'.
------------------------------------------------------------------------
r122971 | tseaver | 2011-09-27 13:31:03 -0400 (Tue, 27 Sep 2011) | 1 line

Document additional picklecache methods.
parent 35be0511
...@@ -39,6 +39,13 @@ try: ...@@ -39,6 +39,13 @@ try:
except ImportError: except ImportError:
from picklecache import PickleCache from picklecache import PickleCache
try:
import TimeStamp
except ImportError:
import timestamp as TimeStamp
import sys
sys.modules['persistent.TimeStamp'] = sys.modules['persistent.timestamp']
if _HAVE_CPERSISTENCE: if _HAVE_CPERSISTENCE:
# Make an interface declaration for Persistent, if zope.interface # Make an interface declaration for Persistent, if zope.interface
# is available. XXX that the pyPersistent version already does this? # is available. XXX that the pyPersistent version already does this?
......
...@@ -537,6 +537,16 @@ class IPickleCache(Interface): ...@@ -537,6 +537,16 @@ class IPickleCache(Interface):
remove it from the ring. remove it from the ring.
""" """
def debug_info():
"""Return debugging data about objects in the cache.
o Return a sequence of tuples, (oid, refcount, typename, state).
"""
def update_object_size_estimation(oid, new_size):
"""Update the cache's size estimation for 'oid', if known to the cache.
"""
cache_size = Attribute(u'Target size of the cache') cache_size = Attribute(u'Target size of the cache')
cache_drain_resistance = Attribute(u'Factor for draining cache below ' cache_drain_resistance = Attribute(u'Factor for draining cache below '
u'target size') u'target size')
......
...@@ -65,7 +65,8 @@ class PickleCache(object): ...@@ -65,7 +65,8 @@ class PickleCache(object):
raise ValueError('OID must be string: %s' % oid) raise ValueError('OID must be string: %s' % oid)
# XXX # XXX
if oid in self.persistent_classes or oid in self.data: if oid in self.persistent_classes or oid in self.data:
raise KeyError('Duplicate OID: %s' % oid) if self.data[oid] is not value:
raise KeyError('Duplicate OID: %s' % oid)
if type(value) is type: if type(value) is type:
self.persistent_classes[oid] = value self.persistent_classes[oid] = value
else: else:
...@@ -226,6 +227,11 @@ class PickleCache(object): ...@@ -226,6 +227,11 @@ class PickleCache(object):
)) ))
return result return result
def update_object_size_estimation(self, oid, new_size):
""" See IPickleCache.
"""
pass
cache_size = property(lambda self: self.target_size) cache_size = property(lambda self: self.target_size)
cache_drain_resistance = property(lambda self: self.drain_resistance) cache_drain_resistance = property(lambda self: self.drain_resistance)
cache_non_ghost_count = property(lambda self: self.non_ghost_count) cache_non_ghost_count = property(lambda self: self.non_ghost_count)
...@@ -254,4 +260,3 @@ class PickleCache(object): ...@@ -254,4 +260,3 @@ class PickleCache(object):
break break
elif oid in self.persistent_classes: elif oid in self.persistent_classes:
del self.persistent_classes[oid] del self.persistent_classes[oid]
...@@ -80,7 +80,7 @@ class Persistent(object): ...@@ -80,7 +80,7 @@ class Persistent(object):
__slots__ = ('__jar', '__oid', '__serial', '__flags', '__size') __slots__ = ('__jar', '__oid', '__serial', '__flags', '__size')
implements(IPersistent) implements(IPersistent)
def __new__(cls): def __new__(cls, *args, **kw):
inst = super(Persistent, cls).__new__(cls) inst = super(Persistent, cls).__new__(cls)
inst.__jar = None inst.__jar = None
inst.__oid = None inst.__oid = None
......
...@@ -92,6 +92,7 @@ class PickleCacheTests(unittest.TestCase): ...@@ -92,6 +92,7 @@ class PickleCacheTests(unittest.TestCase):
cache = self._makeOne() cache = self._makeOne()
original = self._makePersist() original = self._makePersist()
cache['original'] = original cache['original'] = original
cache['original'] = original # doesn't raise
duplicate = self._makePersist() duplicate = self._makePersist()
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment