-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* flush cache by key * use scan instead of keys command * docs * docs * docs * cms cache controller test and other test stubs * only need two of these * tests * cleaner test * correct cursor * more communicative tests * scan on each node * cms cache entries
- Loading branch information
1 parent
a41217c
commit 8e40c33
Showing
20 changed files
with
413 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import Config | ||
|
||
config :dotcom, :cache, Dotcom.Cache.TestCache | ||
config :dotcom, :redis, Redis.Mock | ||
config :dotcom, :redix, Redix.Mock | ||
config :dotcom, :redix_pub_sub, Redix.PubSub.Mock | ||
config :dotcom, :trip_plan_feedback_cache, Dotcom.Cache.TestCache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Dotcom.Redis.Behaviour do | ||
@moduledoc """ | ||
A behaviour module for NebulexRedisAdapter. | ||
""" | ||
|
||
@callback command(Redix.command()) :: | ||
{:ok, Redix.Protocol.redis_value()} | ||
| {:error, atom() | Redix.Error.t() | Redix.ConnectionError.t()} | ||
|
||
@implementation Application.compile_env!(:dotcom, :redis) | ||
|
||
def command(cmd), do: @implementation.command(cmd) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Dotcom.Redix.Behaviour do | ||
@moduledoc """ | ||
A behaviour module for Redix. | ||
""" | ||
|
||
@callback command(Redix.connection(), Redix.command()) :: | ||
{:ok, Redix.Protocol.redis_value()} | ||
| {:error, atom() | Redix.Error.t() | Redix.ConnectionError.t()} | ||
@callback start_link(String.t() | keyword()) :: {:ok, pid()} | :ignore | {:error, term()} | ||
@callback stop(Redix.connection()) :: :ok | ||
|
||
@implementation Application.compile_env!(:dotcom, :redix) | ||
|
||
def command(conn, cmd), do: @implementation.command(conn, cmd) | ||
def start_link(opts), do: @implementation.start_link(opts) | ||
def stop(conn), do: @implementation.stop(conn) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Dotcom.Redix.PubSub.Behaviour do | ||
@moduledoc """ | ||
A behaviour module for Redix.PubSub. | ||
""" | ||
|
||
@callback start_link(String.t() | keyword()) :: {:ok, pid()} | :ignore | {:error, term()} | ||
@callback subscribe( | ||
Redix.PubSub.connection(), | ||
String.t() | [String.t()], | ||
Redix.PubSub.subscriber() | ||
) :: {:ok, reference()} | ||
|
||
@implementation Application.compile_env!(:dotcom, :redix_pub_sub) | ||
|
||
def start_link(opts), do: @implementation.start_link(opts) | ||
|
||
def subscribe(conn, channels, subscriber), | ||
do: @implementation.subscribe(conn, channels, subscriber) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
defmodule DotcomWeb.CacheController do | ||
@moduledoc """ | ||
A controller that allows us to interact with the cache. | ||
Currently, we only support deleting keys from the cache. | ||
""" | ||
|
||
require Logger | ||
|
||
use DotcomWeb, :controller | ||
|
||
@cache Application.compile_env!(:dotcom, :cache) | ||
|
||
@doc """ | ||
Flushes the cache given a key in the path. | ||
Simply use a / in the path where you would use a | in the key. | ||
Wildcards are supported. | ||
Examples: | ||
/cache/stops.repo/stop/* -> stops.repo|stop|* | ||
/cache/stops.repo/stop/1 -> stops.repo|stop|1 | ||
""" | ||
def flush_cache_keys(conn, %{"path" => path}) do | ||
key = Enum.join(path, "|") | ||
|
||
try do | ||
Kernel.apply(@cache, flush_cache_function(@cache), [key]) | ||
rescue | ||
e in Redix.ConnectionError -> | ||
Logger.warning("dotcom_web.cache_controller.error error=redis-#{e.reason}") | ||
|
||
e in Redix.Error -> | ||
Logger.warning("dotcom_web.cache_controller.error error=redis-#{e.message}") | ||
end | ||
|
||
send_resp(conn, 202, "") |> halt() | ||
end | ||
|
||
defp flush_cache_function(cache) do | ||
if cache.__info__(:functions) |> Keyword.has_key?(:flush_keys) do | ||
:flush_keys | ||
else | ||
:delete | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.