Support Memcached for local caching

Created on 18 April 2023, about 1 year ago
Updated 20 April 2023, about 1 year ago

Problem/Motivation

The product page talks about support for Redis, but some hosting platforms offer Memcached instead.

Proposed resolution

Support and document Memcached for sites hosted on platforms where this is available instead of Redis.

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mandclu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mandclu
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    The information on the project page is slightly outdated, as no configuration is required any longer. The module now recognizes the best available caching backend. However, it currently still only supports Redis or the file system. Here is how that's being done:

          if ($redis = Settings::get('redis.connection')) {
            $dns = 'redis://' . ($redis['host'] ?? 'localhost') . ':' . ($redis['port'] ?? '6379');
            $this->cache = new Redis(['redis_dsn' => $dns], $this->logger);
          }
          else {
            $this->cache = new PhpFiles(['fs_cache_path' => $this->fileSystem->getTempDirectory() . '/crowdsec'], $this->logger);
          }
    

    In order to also support Memcached, I need some help from somebody who's used that with Drupal before. Here are 2 questions:

    • How can we recognize that the current Drupal site uses Memcached? As for Redis, this is done by checking for Settings::get('redis.connection').. Is there something similarly available for Memcached?
    • To initialize the Memcached backend for the CrowdSec library, they need a value for memcached_dsn. How would that DSN look like and is that information available from Drupal settings for us to re-use that or do we have to provide some configuration for the site builder to provide that information manually?
  • @jurgenhaas opened merge request.
  • Status changed to Needs review about 1 year ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thanks to the help from @IT-Cru I've started the memcached support. Just not sure about the exact DNS that is required to communicate with memcached, but hopefully somebody can give this a try and let me know, if anything needs to be adjusted.

    It's now implemented such that it looks for the Redis backend first, Memcached second, and if none of them were available, it falls back to the file system.

Production build 0.69.0 2024