-
-
Notifications
You must be signed in to change notification settings - Fork 1
Local thumbnail caching #1
Description
Add options to provide local thumbnail caching.
- Enable local thumbnail caching
thumbnail_caching1/0, default 1 - Maximum cache time [minutes]
thumbnail_caching_ttl, default 10080 (one week) - Show original when thumbnail unavailable
thumbnail_caching_show_original1/0 default 0 - Maximum time for creating thumbnails [seconds]
thumbnail_caching_timeoutinteger default 10
All options are hidden whenlambdaResizeis 1 orpreviewis anything other thanalways.
The plugin creates a cache folder under media/plg_filesystem_s3 for each filesystem root defined in the plugin. The name of the folder is 'thumb_' . crc32($title) . '_' . strtolower(substr($title, 0, 5));
Start a timer.
For each file listed in a folder we calculate a unique key as md5($path . "\0" . $fileName . "\0" . $size . "\0" . $modifiedTimestamp). This creates a key like 0123456789abcdef0123456789abcdef.
We will create folders in the cache path three levels deep to store thumbnail files (with the same extension as the original), e.g. 01\23\45\0123456789abcdef0123456789abcdef.png.
If the local file exists and its last modification time is later than time() - $thumbnail_caching_ttl we skip over it. If the file size is over 1 predefined size (let's say 10MB) we also skip over it.
Otherwise, we proceed as follows:
- If Lambda Resize is enabled we use the existing algorithm; resizing is handled at AWS.
- If Lambda Resize is disabled we download the file from the S3 bucket and create a resized thumbnail with maximum dimensions of 100 pixels. Use the URL to the locally cached thumbnail as the file record's
thumb_pathproperty.
If the timer says we are over the thumbnail_caching_timeout time limit we only check for existing local thumbnail files. If there is none, we return the URL to media/plg_filesystem_s3/images/no_preview_yet.svg or the URL to the original image, depending on the value of thumbnail_caching_show_original.