Current section

Files

Jump to
ecto_struct_cachex lib decorator cache_evict.ex
Raw

lib/decorator/cache_evict.ex

defmodule ESC.Decorator.CacheEvict do
@moduledoc false
alias ESC.{Cache, Config, Hook}
defmacro __using__(_opts) do
quote do
def cache_evict(struct_name, block, %Decorator.Decorate.Context{args: args_expr} = ctx) do
impl_m = __MODULE__
quote do
with(
false = _disable <- Config.get_disable(),
exec_block <- fn -> unquote(block) end,
struct_name <- unquote(struct_name),
[conds_or_id | _] <- unquote(args_expr)
) do
Cache.delete(struct_name, conds_or_id, exec_block)
else
true -> unquote(block)
_ -> :args_is_empty
end
|> Hook.post_hook(unquote(impl_m))
end
end
end
end
end