• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

whitfin / cachex / 547c98a66615bbc699e87cc71c05cf5f1b6e0e5a

11 Jun 2024 11:37PM UTC coverage: 99.846% (-0.2%) from 100.0%
547c98a66615bbc699e87cc71c05cf5f1b6e0e5a

push

github

web-flow
Ensure fetch fallback is called once per key per ttl (#348)

14 of 14 new or added lines in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

648 of 649 relevant lines covered (99.85%)

660.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/lib/cachex/policy/lrw/evented.ex
1
defmodule Cachex.Policy.LRW.Evented do
2
  @moduledoc """
3
  Evented least recently written eviction policy for Cachex.
4

5
  This module implements an evented LRW eviction policy for Cachex, using a hook
6
  to listen for new key additions to a cache and enforcing bounds in a reactive
7
  way. This policy enforces cache bounds and limits far more accurately than other
8
  scheduled implementations, but comes at a higher memory cost (due to the message
9
  passing between hooks).
10
  """
11
  use Cachex.Hook
12

13
  # import macros
14
  import Cachex.Spec
15

16
  # add internal aliases
17
  alias Cachex.Policy.LRW
18

19
  # actions which didn't trigger a write
20
  @ignored [:error, :ignored]
21

22
  ######################
23
  # Hook Configuration #
24
  ######################
25

26
  @doc """
27
  Returns the actions this policy should listen on.
28
  """
29
  @spec actions :: [atom]
30
  def actions,
3,835✔
31
    do: [
32
      :put,
33
      :decr,
34
      :incr,
35
      :fetch,
36
      :update,
37
      :put_many,
38
      :get_and_update
39
    ]
40

41
  @doc """
42
  Returns the provisions this policy requires.
43
  """
44
  @spec provisions :: [atom]
45
  def provisions,
4✔
46
    do: [:cache]
47

48
  ####################
49
  # Server Callbacks #
50
  ####################
51

52
  @doc false
53
  # Initializes this policy using the limit being enforced.
54
  def init(limit() = limit),
2✔
55
    do: {:ok, {nil, limit}}
56

57
  @doc false
58
  # Handles notification of a cache action.
59
  #
60
  # This will check if the action can modify the size of the cache, and if so will
61
  # execute the boundary enforcement to trim the size as needed.
62
  #
63
  # Note that this will ignore error results and only operates on actions which are
64
  # able to cause a net gain in cache size (so removals are also ignored).
65
  def handle_notify(_message, {status, _value}, {cache, limit} = opts)
66
      when status not in @ignored do
67
    LRW.apply_limit(cache, limit)
202✔
68
    {:ok, opts}
69
  end
70

UNCOV
71
  def handle_notify(_message, _result, opts),
×
72
    do: {:ok, opts}
73

74
  @doc false
75
  # Receives a provisioned cache instance.
76
  #
77
  # The provided cache is then stored in the cache and used for cache calls going
78
  # forwards, in order to skip the lookups inside the cache overseer for performance.
79
  def handle_provision({:cache, cache}, {_cache, limit}),
2✔
80
    do: {:ok, {cache, limit}}
81
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc