(fmn) Use on-disk cache but in-memory lock

This commit is contained in:
Ralph Bean 2015-02-12 17:20:19 +00:00
parent 214410fde2
commit a6d00b67c7

View file

@ -8,6 +8,31 @@ ircnick = "fedora-notifs"
base = "https://apps.%s/notifications/" % domain
from dogpile.core.readwrite_lock import ReadWriteMutex
from dogpile.cache.backends.file import AbstractFileLock
class MutexLock(AbstractFileLock):
""" Use an in-memory lock for our dogpile cache
in an attempt to reduce thread competition.
"""
def __init__(self, filename):
self.mutex = ReadWriteMutex()
def acquire_read_lock(self, wait):
ret = self.mutex.acquire_read_lock(wait)
return wait or ret
def acquire_write_lock(self, wait):
ret = self.mutex.acquire_write_lock(wait)
return wait or ret
def release_read_lock(self):
return self.mutex.release_read_lock()
def release_write_lock(self):
return self.mutex.release_write_lock()
config = {
{% if env == 'staging' %}
# Pull in messages from production so we can more thoroughly test in stg.
@ -56,6 +81,7 @@ config = {
"expiration_time": 56700,
"arguments": {
"filename": "/dev/shm/fmn-cache.dbm",
"lock_factory": MutexLock, # Use on-disk cache but in-memory lock.
},
},