summaryrefslogtreecommitdiff
path: root/test/support/null_cache.ex
blob: 9f1d45f1df5a75d2aed90735a1043bdb85952efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.NullCache do
  @moduledoc """
  A module simulating a permanently empty cache.
  """
  @behaviour Pleroma.Caching

  @impl true
  def get!(_, _), do: nil

  @impl true
  def put(_, _, _, _ \\ nil), do: {:ok, true}

  @impl true
  def stream!(_, _), do: []

  @impl true
  def get(_, _), do: {:ok, nil}

  @impl true
  def fetch!(_, key, func) do
    case func.(key) do
      {_, res} -> res
      res -> res
    end
  end

  @impl true
  def get_and_update(_, _, func) do
    func.(nil)
  end

  @impl true
  def expire_at(_, _, _), do: {:ok, true}

  @impl true
  def exists?(_, _), do: {:ok, false}

  @impl true
  def execute!(_, func) do
    func.(:nothing)
  end

  @impl true
  def del(_, _), do: {:ok, true}
end