mirror of
https://github.com/evennia/evennia.git
synced 2026-04-04 06:57:16 +02:00
Implemented WeakSharedMemoryModel for Attributes.
This commit is contained in:
parent
f67effa0f9
commit
9bfb829274
4 changed files with 35 additions and 6 deletions
|
|
@ -271,6 +271,27 @@ class SharedMemoryModel(Model):
|
|||
#blockingCallFromThread(reactor, _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.
|
||||
def flush_cache(**kwargs):
|
||||
def class_hierarchy(root):
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
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