diff --git a/apps/api_web/config/config.exs b/apps/api_web/config/config.exs index f2dbe135..7b63f9c4 100644 --- a/apps/api_web/config/config.exs +++ b/apps/api_web/config/config.exs @@ -23,6 +23,13 @@ config :api_web, ApiWeb.Endpoint, config :api_web, :signing_salt, "NdisAeo6Jf02spiKqa" +config :api_web, RateLimiter.Memcache, + connection_opts: [ + namespace: "api_dev_rate_limit", + hostname: "localhost", + coder: Memcache.Coder.JSON + ] + config :api_web, :rate_limiter, clear_interval: 60_000, limiter: ApiWeb.RateLimiter.ETS, diff --git a/apps/api_web/config/test.exs b/apps/api_web/config/test.exs index 08474ac5..88af1335 100644 --- a/apps/api_web/config/test.exs +++ b/apps/api_web/config/test.exs @@ -13,7 +13,8 @@ config :api_web, :rate_limiter, config :api_web, RateLimiter.Memcache, connection_opts: [ namespace: "api_test_rate_limit", - hostname: "localhost" + hostname: "localhost", + coder: Memcache.Coder.JSON ] config :api_web, ApiWeb.Plugs.ModifiedSinceHandler, check_caller: true diff --git a/apps/api_web/lib/api_web/rate_limiter/memcache/supervisor.ex b/apps/api_web/lib/api_web/rate_limiter/memcache/supervisor.ex index 9547a82d..ff2c39be 100644 --- a/apps/api_web/lib/api_web/rate_limiter/memcache/supervisor.ex +++ b/apps/api_web/lib/api_web/rate_limiter/memcache/supervisor.ex @@ -15,7 +15,11 @@ defmodule ApiWeb.RateLimiter.Memcache.Supervisor do if memcache_required?() do clear_interval_ms = Keyword.fetch!(@rate_limit_config, :clear_interval) clear_interval = div(clear_interval_ms, 1000) - connection_opts_config = Keyword.fetch!(@rate_limit_config, :connection_opts) + + connection_opts_config = + Application.fetch_env!(:api_web, RateLimiter.Memcache) + |> Keyword.fetch!(:connection_opts) + connection_opts = [ttl: clear_interval * 2] ++ connection_opts_config workers =