Support Redis cache in redundant_attachments plugin

pull/6218/head
Aleksander Machniak 6 years ago
parent 5410c6112b
commit 6e7afe5360

@ -2,7 +2,7 @@
// By default this plugin stores attachments in filesystem // By default this plugin stores attachments in filesystem
// and copies them into sql database. // and copies them into sql database.
// You can change it to use 'memcache' or 'apc'. // You can change it to use 'memcache', 'redis' or 'apc'.
// ----------------------------------------------------------- // -----------------------------------------------------------
// WARNING: Remember to set max_allowed_packet in database or // WARNING: Remember to set max_allowed_packet in database or
// config to match with expected max attachment size. // config to match with expected max attachment size.

@ -13,6 +13,8 @@
* @author Ziba Scott <ziba@umich.edu> * @author Ziba Scott <ziba@umich.edu>
* @author Aleksander Machniak <alec@alec.pl> * @author Aleksander Machniak <alec@alec.pl>
* *
* Copyright (C) 2011-2018, The Roundcube Dev Team
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 * it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation. * as published by the Free Software Foundation.

@ -3,7 +3,7 @@
"type": "roundcube-plugin", "type": "roundcube-plugin",
"description": "This plugin provides a redundant storage for temporary uploaded attachment files. They are stored in both the database backend as well as on the local file system. It provides also memcache store as a fallback.", "description": "This plugin provides a redundant storage for temporary uploaded attachment files. They are stored in both the database backend as well as on the local file system. It provides also memcache store as a fallback.",
"license": "GPLv2", "license": "GPLv2",
"version": "1.1", "version": "1.2",
"authors": [ "authors": [
{ {
"name": "Aleksander Machniak", "name": "Aleksander Machniak",

@ -1,14 +1,15 @@
<?php <?php
// By default this plugin stores attachments in filesystem // By default this plugin stores attachments in filesystem and copies them into sql database.
// and copies them into sql database. // In environments with replicated database it is possible to use memcache or redis
// In environments with replicated database it is possible // as a fallback when write-master is unavailable.
// to use memcache as a fallback when write-master is unavailable. // -------------------------------------------------------------------------------------
// ------------------------------------------------------------ // WARNING: Remember to also set memcache_max_allowed_packet or redis_max_allowed_packet
// WARNING: Remember to also set memcache_max_allowed_packet in // in config to match with expected maximum attachment size.
// config to match with expected max attachment size. // -------------------------------------------------------------------------------------
// ------------------------------------------------------------ // This option can be set to 'memcache' or 'redis'.
$config['redundant_attachments_memcache'] = false; // Don't forget to set redis_*/memcache_* options in Roundcube config file.
$config['redundant_attachments_fallback'] = false;
// Attachment data expires after specified TTL time in seconds (max.2592000). // Attachment data expires after specified TTL time in seconds (max.2592000).
// Default is 12 hours. // Default is 12 hours.

@ -7,7 +7,7 @@
* attachment files. They are stored in both the database backend * attachment files. They are stored in both the database backend
* as well as on the local file system. * as well as on the local file system.
* *
* It provides also memcache store as a fallback (see config file). * It provides also memcache/redis store as a fallback (see config file).
* *
* This plugin relies on the core filesystem_attachments plugin * This plugin relies on the core filesystem_attachments plugin
* and combines it with the functionality of the database_attachments plugin. * and combines it with the functionality of the database_attachments plugin.
@ -15,8 +15,8 @@
* @author Thomas Bruederli <roundcube@gmail.com> * @author Thomas Bruederli <roundcube@gmail.com>
* @author Aleksander Machniak <machniak@kolabsys.com> * @author Aleksander Machniak <machniak@kolabsys.com>
* *
* Copyright (C) 2011, The Roundcube Dev Team * Copyright (C) 2011-2018, The Roundcube Dev Team
* Copyright (C) 2011, Kolab Systems AG * Copyright (C) 2011-2018, Kolab Systems AG
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 * it under the terms of the GNU General Public License version 2
@ -46,7 +46,7 @@ class redundant_attachments extends filesystem_attachments
// rcube_cache instance for SQL DB // rcube_cache instance for SQL DB
private $cache; private $cache;
// rcube_cache instance for memcache // rcube_cache instance for memcache/redis
private $mem_cache; private $mem_cache;
private $loaded; private $loaded;
@ -66,20 +66,25 @@ class redundant_attachments extends filesystem_attachments
// load configuration // load configuration
$this->load_config(); $this->load_config();
$ttl = 12 * 60 * 60; // 12 hours $ttl = 12 * 60 * 60; // 12 hours
$ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl); $ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl);
$prefix = self::PREFIX; $fallback = $rcmail->config->get('redundant_attachments_fallback');
$prefix = self::PREFIX;
if ($id = session_id()) { if ($id = session_id()) {
$prefix .= $id; $prefix .= $id;
} }
if ($fallback === null) {
$fallback = $rcmail->config->get('redundant_attachments_memcache') ? 'memcache' : null; // BC
}
// Init SQL cache (disable cache data serialization) // Init SQL cache (disable cache data serialization)
$this->cache = $rcmail->get_cache($prefix, 'db', $ttl, false); $this->cache = $rcmail->get_cache($prefix, 'db', $ttl, false);
// Init memcache (fallback) cache // Init memcache/redis (fallback) cache
if ($rcmail->config->get('redundant_attachments_memcache')) { if ($fallback) {
$this->mem_cache = $rcmail->get_cache($prefix, 'memcache', $ttl, false); $this->mem_cache = $rcmail->get_cache($prefix, $fallback, $ttl, false);
} }
$this->loaded = true; $this->loaded = true;

Loading…
Cancel
Save