Implemented WeakSharedMemoryModel for Attributes.
This commit is contained in:
parent
f67effa0f9
commit
9bfb829274
4 changed files with 35 additions and 6 deletions
|
|
@ -35,6 +35,7 @@ command line. The process is as follows:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from weakref import WeakValueDictionary
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||||
|
|
@ -42,13 +43,13 @@ from django.conf import settings
|
||||||
from src.comms.channelhandler import CHANNELHANDLER
|
from src.comms.channelhandler import CHANNELHANDLER
|
||||||
from src.utils import logger, utils
|
from src.utils import logger, utils
|
||||||
from src.commands.cmdparser import at_multimatch_cmd
|
from src.commands.cmdparser import at_multimatch_cmd
|
||||||
from src.utils.utils import string_suggestions, make_iter, to_unicode
|
from src.utils.utils import string_suggestions, to_unicode
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
__all__ = ("cmdhandler",)
|
__all__ = ("cmdhandler",)
|
||||||
_GA = object.__getattribute__
|
_GA = object.__getattribute__
|
||||||
_CMDSET_MERGE_CACHE = {}
|
_CMDSET_MERGE_CACHE = WeakValueDictionary()
|
||||||
|
|
||||||
# This decides which command parser is to be used.
|
# This decides which command parser is to be used.
|
||||||
# You have to restart the server for changes to take effect.
|
# You have to restart the server for changes to take effect.
|
||||||
|
|
@ -408,6 +409,13 @@ def cmdhandler(called_by, raw_string, testing=False, callertype="session", sessi
|
||||||
caller.ndb.last_cmd = yield copy(cmd)
|
caller.ndb.last_cmd = yield copy(cmd)
|
||||||
else:
|
else:
|
||||||
caller.ndb.last_cmd = None
|
caller.ndb.last_cmd = None
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
del cmd.caller
|
||||||
|
del cmd.player
|
||||||
|
del cmd.session
|
||||||
|
del cmd.cmdset
|
||||||
|
|
||||||
# Done! This returns a deferred. By default, Evennia does
|
# Done! This returns a deferred. By default, Evennia does
|
||||||
# not use this at all.
|
# not use this at all.
|
||||||
returnValue(ret)
|
returnValue(ret)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ from django.conf import settings
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
from src.utils.idmapper.models import SharedMemoryModel
|
from src.utils.idmapper.models import SharedMemoryModel, WeakSharedMemoryModel
|
||||||
from src.server.caches import get_prop_cache, set_prop_cache
|
from src.server.caches import get_prop_cache, set_prop_cache
|
||||||
#from src.server.caches import set_attr_cache
|
#from src.server.caches import set_attr_cache
|
||||||
|
|
||||||
|
|
@ -44,7 +44,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
|
from src.utils import logger
|
||||||
from src.utils.utils import make_iter, is_iter, to_str, inherits_from, LazyLoadHandler, NonWeakLazyLoadHandler
|
from src.utils.utils import make_iter, is_iter, to_str, inherits_from, LazyLoadHandler
|
||||||
from src.utils.dbserialize import to_pickle, from_pickle
|
from src.utils.dbserialize import to_pickle, from_pickle
|
||||||
from src.utils.picklefield import PickledObjectField
|
from src.utils.picklefield import PickledObjectField
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ _DA = object.__delattr__
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
|
|
||||||
#class Attribute(SharedMemoryModel):
|
#class Attribute(SharedMemoryModel):
|
||||||
class Attribute(models.Model):
|
class Attribute(WeakSharedMemoryModel):
|
||||||
"""
|
"""
|
||||||
Abstract django model.
|
Abstract django model.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,27 @@ class SharedMemoryModel(Model):
|
||||||
#blockingCallFromThread(reactor, _save_callback, cls, *args, **kwargs)
|
#blockingCallFromThread(reactor, _save_callback, cls, *args, **kwargs)
|
||||||
callFromThread(_save_callback, cls, *args, **kwargs)
|
callFromThread(_save_callback, cls, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class WeakSharedMemoryModelBase(SharedMemoryModelBase):
|
||||||
|
"""
|
||||||
|
Uses a WeakValue dictionary for caching instead of a regular one
|
||||||
|
"""
|
||||||
|
def _prepare(cls):
|
||||||
|
cls.__instance_cache__ = WeakValueDictionary()
|
||||||
|
super(WeakSharedMemoryModelBase, cls)._prepare()
|
||||||
|
|
||||||
|
class WeakSharedMemoryModel(SharedMemoryModel):
|
||||||
|
"""
|
||||||
|
Uses a WeakValue dictionary for caching instead of a regular one
|
||||||
|
"""
|
||||||
|
__metaclass__ = WeakSharedMemoryModelBase
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
def flush_instance_cache(cls):
|
||||||
|
cls.__instance_cache__ = WeakValueDictionary()
|
||||||
|
flush_instance_cache = classmethod(flush_instance_cache)
|
||||||
|
|
||||||
|
|
||||||
# Use a signal so we make sure to catch cascades.
|
# Use a signal so we make sure to catch cascades.
|
||||||
def flush_cache(**kwargs):
|
def flush_cache(**kwargs):
|
||||||
def class_hierarchy(root):
|
def class_hierarchy(root):
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
from django.db.models import *
|
from django.db.models import *
|
||||||
from base import SharedMemoryModel
|
from base import SharedMemoryModel, WeakSharedMemoryModel
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue