From c6de76822e6dcd2ba6db213c494a950d7f7d0688 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 7 Jul 2017 02:16:23 -0400 Subject: [PATCH] Add two new setting options to control the caching of page images. DOCUMENTS_DISABLE_BASE_IMAGE_CACHE and DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE. Signed-off-by: Roberto Rosario --- docs/releases/2.5.rst | 12 ++++++++++++ mayan/apps/documents/models.py | 8 ++++++-- mayan/apps/documents/settings.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/releases/2.5.rst b/docs/releases/2.5.rst index e348405a14..bed31b1810 100644 --- a/docs/releases/2.5.rst +++ b/docs/releases/2.5.rst @@ -65,6 +65,18 @@ Other Changes - Add "Remember me" checkbox in the login form. - Add AUTHENTICATION_MAXIMUM_SESSION_LENGTH configuration setting for the maximum time an user's login session will remain valid. Defaults to 30 days. +- Ability to disable the document page image caching. This feature is controlled + by two new settings: DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE and + DOCUMENTS_DISABLE_BASE_IMAGE_CACHE. DOCUMENTS_DISABLE_BASE_IMAGE_CACHE + disables the first layer of caching, the generation of a master image file + for each document page. This means that subsequent request for a page's + image will trigger the conversion of the document from its original + uploaded file. The second option, DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE, + disables just the caching of the transformed (rotated, resized, zoomed) + images of document pages. The settings can be used together or separately + depending on how much disk space saving is desired. These settings give control + over the trade-off between disk space savings and higher CPU utilization. + Removals -------- diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 15b2a0fbeb..32c2ee4c5c 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -36,6 +36,7 @@ from .managers import ( from .permissions import permission_document_view from .runtime import cache_storage_backend, storage_backend from .settings import ( + setting_disable_base_image_cache, setting_disable_transformed_image_cache, setting_display_size, setting_language, setting_zoom_max_level, setting_zoom_min_level ) @@ -768,11 +769,14 @@ class DocumentPage(models.Model): # Check is transformed image is available logger.debug('transformations cache filename: %s', cache_filename) - if cache_storage_backend.exists(cache_filename): + if not setting_disable_transformed_image_cache.value and cache_storage_backend.exists(cache_filename): logger.debug( 'transformations cache file "%s" found', cache_filename ) else: + logger.debug( + 'transformations cache file "%s" not found', cache_filename + ) image = self.get_image(transformations=transformation_list) with cache_storage_backend.open(cache_filename, 'wb+') as file_object: file_object.write(image.getvalue()) @@ -785,7 +789,7 @@ class DocumentPage(models.Model): cache_filename = self.cache_filename logger.debug('Page cache filename: %s', cache_filename) - if cache_storage_backend.exists(cache_filename): + if not setting_disable_base_image_cache.value and cache_storage_backend.exists(cache_filename): logger.debug('Page cache file "%s" found', cache_filename) converter = converter_class( file_object=cache_storage_backend.open(cache_filename) diff --git a/mayan/apps/documents/settings.py b/mayan/apps/documents/settings.py index 3b818cc4dc..b298254dbf 100644 --- a/mayan/apps/documents/settings.py +++ b/mayan/apps/documents/settings.py @@ -73,3 +73,18 @@ setting_language_choices = namespace.add_setting( global_name='DOCUMENTS_LANGUAGE_CHOICES', default=LANGUAGE_CHOICES, help_text=_('List of supported document languages.') ) +setting_disable_base_image_cache = namespace.add_setting( + global_name='DOCUMENTS_DISABLE_BASE_IMAGE_CACHE', default=False, + help_text=_( + 'Disables the first cache tier which stores high resolution, ' + 'non transformed versions of documents\'s pages.' + ) +) +setting_disable_transformed_image_cache = namespace.add_setting( + global_name='DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE', default=False, + help_text=_( + 'Disables the second cache tier which stores medium to low ' + 'resolution, transformed (rotated, zoomed, etc) versions ' + 'of documents\' pages.' + ) +)