Caching: Initial experitmental cache model

signed-off-by: Roberto Rosario <rosarior@t60.lan>
This commit is contained in:
Roberto Rosario
2018-11-30 19:48:26 -04:00
parent f25174bd15
commit a414b8df92
6 changed files with 148 additions and 4 deletions
+7 -3
View File
@@ -4,7 +4,7 @@ from datetime import timedelta
from kombu import Exchange, Queue
from django.db.models.signals import post_delete
from django.db.models.signals import post_delete, post_migrate
from django.utils.translation import ugettext_lazy as _
from acls import ModelPermission
@@ -48,8 +48,8 @@ from .events import (
event_document_view
)
from .handlers import (
create_default_document_type, handler_remove_empty_duplicates_lists,
handler_scan_duplicates_for,
create_default_document_type, handler_create_document_cache,
handler_remove_empty_duplicates_lists, handler_scan_duplicates_for,
)
from .links import (
link_clear_image_cache, link_document_clear_transformations,
@@ -591,6 +591,10 @@ class DocumentsApp(MayanAppConfig):
create_default_document_type,
dispatch_uid='create_default_document_type'
)
post_migrate.connect(
dispatch_uid='documents_handler_create_document_cache',
receiver=handler_create_document_cache,
)
post_version_upload.connect(
handler_scan_duplicates_for,
dispatch_uid='handler_scan_duplicates_for',
+9
View File
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.apps import apps
from django.utils.translation import ugettext_lazy as _
from .literals import DEFAULT_DOCUMENT_TYPE_LABEL
from .signals import post_initial_document_type
@@ -21,6 +22,14 @@ def create_default_document_type(sender, **kwargs):
)
def handler_create_document_cache(sender, **kwargs):
Cache = apps.get_model(app_label='common', model_name='Cache')
Cache.objects.get_or_create(
name='document_images', label=_('Document images'),
storage_instance_path='documents.storages.storage_documentimagecache'
)
def handler_scan_duplicates_for(sender, instance, **kwargs):
task_scan_duplicates_for.apply_async(
kwargs={'document_id': instance.document.pk}
+1
View File
@@ -9,6 +9,7 @@ CHECK_TRASH_PERIOD_INTERVAL = 60
DELETE_STALE_STUBS_INTERVAL = 60 * 10 # 10 minutes
DEFAULT_DELETE_PERIOD = 30
DEFAULT_DELETE_TIME_UNIT = TIME_DELTA_UNIT_DAYS
DEFAULT_DOCUMENTS_CACHE_MAXIMUM_SIZE = 50 * 2 ** 20 # 50 Megabytes
DEFAULT_LANGUAGE = 'eng'
DEFAULT_LANGUAGE_CODES = (
'ilo', 'run', 'uig', 'hin', 'pan', 'pnb', 'wuu', 'msa', 'kxd', 'ind',
+12 -1
View File
@@ -7,7 +7,9 @@ from django.utils.translation import ugettext_lazy as _
from smart_settings import Namespace
from .literals import DEFAULT_LANGUAGE, DEFAULT_LANGUAGE_CODES
from .literals import (
DEFAULT_DOCUMENTS_CACHE_MAXIMUM_SIZE, DEFAULT_LANGUAGE, DEFAULT_LANGUAGE_CODES
)
namespace = Namespace(name='documents', label=_('Documents'))
@@ -25,6 +27,15 @@ setting_documentimagecache_storage_arguments = namespace.add_setting(
'Arguments to pass to the DOCUMENT_CACHE_STORAGE_BACKEND.'
)
)
setting_document_cache_maximum_size = namespace.add_setting(
global_name='DOCUMENTS_CACHE_MAXIMUM_SIZE',
default=DEFAULT_DOCUMENTS_CACHE_MAXIMUM_SIZE,
help_text=_(
'The threshold at which the DOCUMENT_CACHE_STORAGE_BACKEND will start '
'deleting the oldest document image cache files. Specify the size in '
'bytes.'
)
)
setting_disable_base_image_cache = namespace.add_setting(
global_name='DOCUMENTS_DISABLE_BASE_IMAGE_CACHE', default=False,
help_text=_(