Added at_idmapper_flush to allow objects more control of their flush characteristics.

This commit is contained in:
Griatch 2016-10-02 19:14:22 +02:00
parent cd616caf29
commit 15025c0586
6 changed files with 74 additions and 33 deletions

View file

@ -325,6 +325,14 @@ class AttributeHandler(object):
self._catcache.pop(catkey, None)
self._cache_complete = False
def reset_cache(self):
"""
Reset cache from the outside.
"""
self._cache_complete = False
self._cache = {}
self._catcache = {}
def has(self, key=None, category=None):
"""
Checks if the given Attribute (or list of Attributes) exists on
@ -910,7 +918,6 @@ class NAttributeHandler(object):
"""
self._store[key] = value
self.obj.set_recache_protection()
def remove(self, key):
"""
@ -922,7 +929,6 @@ class NAttributeHandler(object):
"""
if key in self._store:
del self._store[key]
self.obj.set_recache_protection(self._store)
def clear(self):
"""

View file

@ -376,6 +376,27 @@ class TypedObject(SharedMemoryModel):
raise Exception("dbref cannot be deleted!")
dbref = property(__dbref_get, __dbref_set, __dbref_del)
def at_idmapper_flush(self):
"""
This is called when the idmapper cache is flushed and
allows customized actions when this happens.
Returns:
do_flush (bool): If True, flush this object as normal. If
False, don't flush and expect this object to handle
the flushing on its own.
"""
if self.nattributes.all():
# we can't flush this object if we have non-persistent
# attributes stored - those would get lost! Nevertheless
# we try to flush as many references as we can.
self.attributes.reset_cache()
self.tags.reset_cache()
return False
# a normal flush
return True
#
# Object manipulation methods
#

View file

@ -212,6 +212,13 @@ class TagHandler(object):
self._catcache.pop(catkey, None)
self._cache_complete = False
def reset_cache(self):
"""
Reset the cache from the outside.
"""
self._cache_complete = False
self._cache = {}
self._catcache = {}
def add(self, tag=None, category=None, data=None):
"""