|
|
@ -28,6 +28,7 @@ from twisted.internet import defer |
|
|
|
|
|
|
|
|
|
|
|
from collections import OrderedDict |
|
|
|
from collections import OrderedDict |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import functools |
|
|
|
import functools |
|
|
|
import inspect |
|
|
|
import inspect |
|
|
|
import threading |
|
|
|
import threading |
|
|
@ -38,9 +39,14 @@ logger = logging.getLogger(__name__) |
|
|
|
_CacheSentinel = object() |
|
|
|
_CacheSentinel = object() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CACHE_SIZE_FACTOR = float(os.environ.get("SYNAPSE_CACHE_FACTOR", 0.1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Cache(object): |
|
|
|
class Cache(object): |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, name, max_entries=1000, keylen=1, lru=True, tree=False): |
|
|
|
def __init__(self, name, max_entries=1000, keylen=1, lru=True, tree=False): |
|
|
|
|
|
|
|
max_entries = int(max_entries * CACHE_SIZE_FACTOR) |
|
|
|
|
|
|
|
|
|
|
|
if lru: |
|
|
|
if lru: |
|
|
|
cache_type = TreeCache if tree else dict |
|
|
|
cache_type = TreeCache if tree else dict |
|
|
|
self.cache = LruCache( |
|
|
|
self.cache = LruCache( |
|
|
|