Drop support for Memcached (#18980)

This commit is contained in:
Rijk van Zanten
2023-06-23 08:54:43 -04:00
committed by GitHub
parent 9a0cd33266
commit 513a739b33
11 changed files with 158 additions and 162 deletions

View File

@@ -21,7 +21,7 @@ let sharedSchemaCache: Keyv | null = null;
let lockCache: Keyv | null = null;
let messengerSubscribed = false;
type Store = 'memory' | 'redis' | 'memcache';
type Store = 'memory' | 'redis';
const messenger = getMessenger();
@@ -156,8 +156,6 @@ function getKeyvInstance(store: Store, ttl: number | undefined, namespaceSuffix?
switch (store) {
case 'redis':
return new Keyv(getConfig('redis', ttl, namespaceSuffix));
case 'memcache':
return new Keyv(getConfig('memcache', ttl, namespaceSuffix));
case 'memory':
default:
return new Keyv(getConfig('memory', ttl, namespaceSuffix));
@@ -175,17 +173,5 @@ function getConfig(store: Store = 'memory', ttl: number | undefined, namespaceSu
config.store = new KeyvRedis(env['CACHE_REDIS'] || getConfigFromEnv('CACHE_REDIS_'));
}
if (store === 'memcache') {
const KeyvMemcache = require('keyv-memcache');
// keyv-memcache uses memjs which only accepts a comma separated string instead of an array,
// so we need to join array into a string when applicable. See #7986
const cacheMemcache = Array.isArray(env['CACHE_MEMCACHE'])
? env['CACHE_MEMCACHE'].join(',')
: env['CACHE_MEMCACHE'];
config.store = new KeyvMemcache(cacheMemcache);
}
return config;
}

View File

@@ -127,10 +127,9 @@ PUBLIC_URL="/"
RATE_LIMITER_ENABLED=false
# Where to store the rate limiter counts [memory]
# memory, redis, memcache
# memory, redis
RATE_LIMITER_STORE=memory
# RATE_LIMITER_REDIS="redis://@127.0.0.1:5105"
# RATE_LIMITER_MEMCACHE="localhost:5109"
# The amount of allowed hits per duration [50]
RATE_LIMITER_POINTS=25
@@ -156,14 +155,13 @@ CACHE_ENABLED=false
# List of collections that prevent cache purging when `CACHE_AUTO_PURGE` is enabled. ["directus_activity,directus_presets"]
# CACHE_AUTO_PURGE_IGNORE_LIST="directus_activity,directus_presets"
# memory | redis | memcache
# memory | redis
CACHE_STORE=memory
# How long assets will be cached for in the browser. Sets the max-age value of the Cache-Control header ["30d"]
ASSETS_CACHE_TTL="30d"
# CACHE_REDIS="redis://@127.0.0.1:5105"
# CACHE_MEMCACHE="localhost:5109"
####################################################################################################
### File Storage

View File

@@ -83,7 +83,6 @@ const allowedEnvironmentVars = [
'CACHE_REDIS_HOST',
'CACHE_REDIS_PORT',
'CACHE_REDIS_PASSWORD',
'CACHE_MEMCACHE',
'CACHE_VALUE_MAX_SIZE',
'CACHE_SKIP_ALLOWED',
'CACHE_HEALTHCHECK_THRESHOLD',

View File

@@ -1,6 +1,6 @@
import type { RequestHandler } from 'express';
import ms from 'ms';
import type { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
import type { RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
import env from '../env.js';
import { HitRateLimitException } from '../exceptions/index.js';
import logger from '../logger.js';
@@ -12,7 +12,7 @@ const RATE_LIMITER_GLOBAL_KEY = 'global-rate-limit';
let checkRateLimit: RequestHandler = (_req, _res, next) => next();
export let rateLimiterGlobal: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory;
export let rateLimiterGlobal: RateLimiterRedis | RateLimiterMemory;
if (env['RATE_LIMITER_GLOBAL_ENABLED'] === true) {
validateEnv(['RATE_LIMITER_GLOBAL_STORE', 'RATE_LIMITER_GLOBAL_DURATION', 'RATE_LIMITER_GLOBAL_POINTS']);

View File

@@ -1,6 +1,6 @@
import type { RequestHandler } from 'express';
import ms from 'ms';
import type { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
import type { RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
import env from '../env.js';
import { HitRateLimitException } from '../exceptions/index.js';
import { createRateLimiter } from '../rate-limiter.js';
@@ -10,7 +10,7 @@ import { validateEnv } from '../utils/validate-env.js';
let checkRateLimit: RequestHandler = (_req, _res, next) => next();
export let rateLimiter: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory;
export let rateLimiter: RateLimiterRedis | RateLimiterMemory;
if (env['RATE_LIMITER_ENABLED'] === true) {
validateEnv(['RATE_LIMITER_STORE', 'RATE_LIMITER_DURATION', 'RATE_LIMITER_POINTS']);

View File

@@ -1,6 +1,6 @@
import { merge } from 'lodash-es';
import type { IRateLimiterOptions, IRateLimiterStoreOptions, RateLimiterAbstract } from 'rate-limiter-flexible';
import { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
import { RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
import env from './env.js';
import { getConfigFromEnv } from './utils/get-config-from-env.js';
@@ -17,8 +17,6 @@ export function createRateLimiter(
switch (env['RATE_LIMITER_STORE']) {
case 'redis':
return new RateLimiterRedis(getConfig('redis', configPrefix, configOverrides));
case 'memcache':
return new RateLimiterMemcache(getConfig('memcache', configPrefix, configOverrides));
case 'memory':
default:
return new RateLimiterMemory(getConfig('memory', configPrefix, configOverrides));
@@ -31,12 +29,12 @@ function getConfig(
overrides?: IRateLimiterOptionsOverrides
): IRateLimiterOptions;
function getConfig(
store: 'redis' | 'memcache',
store: 'redis',
configPrefix: string,
overrides?: IRateLimiterOptionsOverrides
): IRateLimiterStoreOptions;
function getConfig(
store: 'memory' | 'redis' | 'memcache' = 'memory',
store: 'memory' | 'redis' = 'memory',
configPrefix = 'RATE_LIMITER',
overrides?: IRateLimiterOptionsOverrides
): IRateLimiterOptions | IRateLimiterStoreOptions {
@@ -48,11 +46,6 @@ function getConfig(
config.storeClient = new Redis(env[`${configPrefix}_REDIS`] || getConfigFromEnv(`${configPrefix}_REDIS_`));
}
if (store === 'memcache') {
const Memcached = require('memcached');
config.storeClient = new Memcached(env[`${configPrefix}_MEMCACHE`], getConfigFromEnv(`${configPrefix}_MEMCACHE_`));
}
delete config.enabled;
delete config.store;