Cleaned up logging
This commit is contained in:
parent
c077cf5cc4
commit
7334271f68
@ -13,15 +13,16 @@ logger = logging.getLogger(__name__)
|
||||
@deconstructible
|
||||
class CachedStorage(Storage):
|
||||
|
||||
CACHE_EXPIRES = 30
|
||||
|
||||
def __init__(self, remote=None, cachedir=None):
|
||||
def __init__(self, remote=None, cachedir=None, expires=600):
|
||||
if not remote:
|
||||
remote = settings.CACHED_STORAGE_REMOTE
|
||||
if not cachedir:
|
||||
cachedir = settings.CACHED_STORAGE_DIR
|
||||
|
||||
self.remote = get_storage_class(remote)()
|
||||
self.cachedir = cachedir
|
||||
self.expires = expires
|
||||
|
||||
os.makedirs(self.cachedir, exist_ok=True)
|
||||
self.clean()
|
||||
|
||||
@ -89,12 +90,12 @@ class CachedStorage(Storage):
|
||||
|
||||
def clean(self):
|
||||
now = time.time()
|
||||
threshold = now - self.CACHE_EXPIRES
|
||||
logger.info("Removing cached files older than %d seconds", self.CACHE_EXPIRES)
|
||||
threshold = now - self.expires
|
||||
logger.info("Removing cached files older than %d seconds", self.expires)
|
||||
for f in os.listdir(self.cachedir):
|
||||
f = os.path.join(self.cachedir, f)
|
||||
s = os.stat(f)
|
||||
if s.st_atime < threshold:
|
||||
logger.debug("Removing %s", f)
|
||||
os.unlink(f)
|
||||
self.next_check = now + 300
|
||||
self.next_check = now + 300 # wait at least 5 minutes before running again
|
||||
|
||||
@ -6,6 +6,9 @@ from django.utils.deconstruct import deconstructible
|
||||
TODO: Create a signal to remove instances from cache if modified
|
||||
'''
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@deconstructible
|
||||
class MultiStorage(Storage):
|
||||
''' Django storage class that proxies multiple storage classes.
|
||||
@ -36,17 +39,15 @@ class MultiStorage(Storage):
|
||||
return self.DELIM.join((storage, name))
|
||||
|
||||
def _proxy(self, method, name, *args, **kwargs):
|
||||
print('PROXY', method, name, *args, **kwargs)
|
||||
storage, p = self.split(name)
|
||||
result = getattr(self.get_storage(storage), method)(p, *args, **kwargs)
|
||||
print("RESULT", result)
|
||||
logger.debug("Proxy: %s(%r, *%r, **%r) => %r", method, name, args, kwargs, result)
|
||||
return result
|
||||
|
||||
def _proxy_name(self, method, name, *args, **kwargs):
|
||||
print('PROXY_NAME', method, name, *args, **kwargs)
|
||||
storage, p = self.split(name)
|
||||
result = getattr(self.get_storage(storage), method)(p, *args, **kwargs)
|
||||
print("RESULT", result)
|
||||
logger.debug("Proxy: %s(%r, *%r, **%r) => %s:%s", method, name, args, kwargs, storage, result)
|
||||
return self.join(storage, result)
|
||||
|
||||
def _open(self, name, mode='rb'):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user