Skip to content

Commit

Permalink
Support Redis cache in redundant_attachments plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Mar 17, 2018
1 parent 5410c61 commit 6e7afe5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion plugins/database_attachments/config.inc.php.dist
Expand Up @@ -2,7 +2,7 @@

// By default this plugin stores attachments in filesystem
// 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
// config to match with expected max attachment size.
Expand Down
2 changes: 2 additions & 0 deletions plugins/database_attachments/database_attachments.php
Expand Up @@ -13,6 +13,8 @@
* @author Ziba Scott <ziba@umich.edu>
* @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
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
Expand Down
2 changes: 1 addition & 1 deletion plugins/redundant_attachments/composer.json
Expand Up @@ -3,7 +3,7 @@
"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.",
"license": "GPLv2",
"version": "1.1",
"version": "1.2",
"authors": [
{
"name": "Aleksander Machniak",
Expand Down
19 changes: 10 additions & 9 deletions plugins/redundant_attachments/config.inc.php.dist
@@ -1,14 +1,15 @@
<?php

// By default this plugin stores attachments in filesystem
// and copies them into sql database.
// In environments with replicated database it is possible
// to use memcache as a fallback when write-master is unavailable.
// ------------------------------------------------------------
// WARNING: Remember to also set memcache_max_allowed_packet in
// config to match with expected max attachment size.
// ------------------------------------------------------------
$config['redundant_attachments_memcache'] = false;
// By default this plugin stores attachments in filesystem and copies them into sql database.
// In environments with replicated database it is possible to use memcache or redis
// as a fallback when write-master is unavailable.
// -------------------------------------------------------------------------------------
// WARNING: Remember to also set memcache_max_allowed_packet or redis_max_allowed_packet
// in config to match with expected maximum attachment size.
// -------------------------------------------------------------------------------------
// This option can be set to 'memcache' or 'redis'.
// 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).
// Default is 12 hours.
Expand Down
25 changes: 15 additions & 10 deletions plugins/redundant_attachments/redundant_attachments.php
Expand Up @@ -7,16 +7,16 @@
* 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 (see config file).
* It provides also memcache/redis store as a fallback (see config file).
*
* This plugin relies on the core filesystem_attachments plugin
* and combines it with the functionality of the database_attachments plugin.
*
* @author Thomas Bruederli <roundcube@gmail.com>
* @author Aleksander Machniak <machniak@kolabsys.com>
*
* Copyright (C) 2011, The Roundcube Dev Team
* Copyright (C) 2011, Kolab Systems AG
* Copyright (C) 2011-2018, The Roundcube Dev Team
* Copyright (C) 2011-2018, Kolab Systems AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
Expand Down Expand Up @@ -46,7 +46,7 @@ class redundant_attachments extends filesystem_attachments
// rcube_cache instance for SQL DB
private $cache;

// rcube_cache instance for memcache
// rcube_cache instance for memcache/redis
private $mem_cache;

private $loaded;
Expand All @@ -66,20 +66,25 @@ private function _load_drivers()
// load configuration
$this->load_config();

$ttl = 12 * 60 * 60; // 12 hours
$ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl);
$prefix = self::PREFIX;
$ttl = 12 * 60 * 60; // 12 hours
$ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl);
$fallback = $rcmail->config->get('redundant_attachments_fallback');
$prefix = self::PREFIX;

if ($id = session_id()) {
$prefix .= $id;
}

if ($fallback === null) {
$fallback = $rcmail->config->get('redundant_attachments_memcache') ? 'memcache' : null; // BC
}

// Init SQL cache (disable cache data serialization)
$this->cache = $rcmail->get_cache($prefix, 'db', $ttl, false);

// Init memcache (fallback) cache
if ($rcmail->config->get('redundant_attachments_memcache')) {
$this->mem_cache = $rcmail->get_cache($prefix, 'memcache', $ttl, false);
// Init memcache/redis (fallback) cache
if ($fallback) {
$this->mem_cache = $rcmail->get_cache($prefix, $fallback, $ttl, false);
}

$this->loaded = true;
Expand Down

0 comments on commit 6e7afe5

Please sign in to comment.