1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Better database cache

This commit is contained in:
Krateng 2019-05-09 16:58:25 +02:00
parent c9048b4ff3
commit 2d87f67322
3 changed files with 16 additions and 5 deletions

View File

@ -9,7 +9,11 @@ from urihandler import uri_to_internal
# doreah toolkit # doreah toolkit
from doreah.logging import log from doreah.logging import log
from doreah import tsv from doreah import tsv
from doreah.caching import Cache from doreah.caching import Cache, DeepCache
try:
from doreah.persistence import DiskDict
except: pass
import doreah
# technical # technical
import os import os
import datetime import datetime
@ -888,14 +892,18 @@ def sync():
### ###
## Caches in front of DB ## Caches in front of DB
## these are intended mainly for excessive site navigation during one session (e.g. constantly going back to the main page to click the next link) ## the volatile caches are intended mainly for excessive site navigation during one session
## the permanent caches are there to save data that is hard to calculate and never changes (old charts)
### ###
import copy import copy
cache_query = {} cache_query = {}
cache_query_permanent = Cache(maxmemory=1024*1024*settings.get_settings("DB_CACHE_SIZE")) if doreah.version >= (0,7,1):
cache_query_permanent = DiskDict(name="dbquery",folder="cache",maxmemory=1024*1024*10,maxstorage=1024*1024*settings.get_settings("DB_CACHE_SIZE"))
else:
cache_query_permanent = Cache(maxmemory=1024*1024*10)
cacheday = (0,0,0) cacheday = (0,0,0)
def db_query(**kwargs): def db_query(**kwargs):
check_cache_age() check_cache_age()
@ -918,7 +926,10 @@ def db_query(**kwargs):
return result return result
cache_aggregate = {} cache_aggregate = {}
cache_aggregate_permanent = Cache(maxmemory=1024*1024*settings.get_settings("DB_CACHE_SIZE")) if doreah.version >= (0,7,1):
cache_aggregate_permanent = DiskDict(name="dbaggregate",folder="cache",maxmemory=1024*1024*10,maxstorage=1024*1024*settings.get_settings("DB_CACHE_SIZE"))
else:
cache_aggregate_permanent = Cache(maxmemory=1024*1024*10)
def db_aggregate(**kwargs): def db_aggregate(**kwargs):
check_cache_age() check_cache_age()
global cache_aggregate, cache_aggregate_permanent global cache_aggregate, cache_aggregate_permanent

Binary file not shown.

View File

@ -12,7 +12,7 @@ CACHE_EXPIRE_POSITIVE = 300 # after how many days positive results should be ref
[Database] [Database]
DB_CACHE_SIZE = 1024 # how many MB the database cache should have available. DB_CACHE_SIZE = 8192 # how many MB on disk each database cache should have available.
[Local Images] [Local Images]