Added the ability to clear an object from the global cache. This is rarely

needed (and can be potentially dangerous if the object depends on certain
startup methods to run and/or holds temporary attributes on themselves -
these will all be lost due to a new instance being created. It is hoever
necessary when it comes to renaming Exits - since the Command on the exit
must then change name too, recaching the Exit will also update the command.
Resolves issue 223.
This commit is contained in:
Griatch 2012-04-15 21:46:43 +02:00
parent 91ec33b9a7
commit 464aa8ca9e
3 changed files with 38 additions and 28 deletions

View file

@ -1015,6 +1015,9 @@ class CmdName(ObjManipCommand):
if aliases: if aliases:
obj.aliases = aliases obj.aliases = aliases
astring = " (%s)" % (", ".join(aliases)) astring = " (%s)" % (", ".join(aliases))
# fix for exits - we need their exit-command to change name too
if obj.destination:
obj.flush_from_cache()
caller.msg("Object's name changed to '%s'%s." % (newname, astring)) caller.msg("Object's name changed to '%s'%s." % (newname, astring))

View file

@ -41,7 +41,7 @@ from src.server.models import ServerConfig
from src.typeclasses import managers from src.typeclasses import managers
from src.locks.lockhandler import LockHandler from src.locks.lockhandler import LockHandler
from src.utils import logger, utils from src.utils import logger, utils
from src.utils.utils import make_iter, is_iter, has_parent, to_unicode, to_str from src.utils.utils import make_iter, is_iter, to_unicode, to_str
__all__ = ("Attribute", "TypeNick", "TypedObject") __all__ = ("Attribute", "TypeNick", "TypedObject")
@ -1447,3 +1447,11 @@ class TypedObject(SharedMemoryModel):
return any(True for hpos, hperm in enumerate(_PERMISSION_HIERARCHY) return any(True for hpos, hperm in enumerate(_PERMISSION_HIERARCHY)
if hperm in [p.lower() for p in self.permissions] and hpos > ppos) if hperm in [p.lower() for p in self.permissions] and hpos > ppos)
return False return False
def flush_from_cache(self):
"""
Flush this object instance from cache, forcing an object reload. Note that this
will kill all temporary attributes on this object since it will be recreated
as a new Typeclass instance.
"""
self.__class__.flush_cached_instance(self)

View file

@ -12,7 +12,6 @@ Evennia changes:
""" """
from twisted.internet import reactor
from django.db.models.base import Model, ModelBase from django.db.models.base import Model, ModelBase
from manager import SharedMemoryManager from manager import SharedMemoryManager