Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/logflare/backends.ex
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ defmodule Logflare.Backends do
@spec clear_list_backends_cache(source_id :: integer()) :: :ok
def clear_list_backends_cache(source_id) when is_integer(source_id) do
Cachex.del(__MODULE__.Cache, {:list_backends, [[source_id: source_id]]})
Cachex.del(__MODULE__.Cache, {:list_backends, [source_id: source_id]})
:ok
end

Expand Down
24 changes: 24 additions & 0 deletions test/logflare/backends/cache_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ defmodule Logflare.Backends.CacheTest do
{:ok, backend: backend, source: source, user: user}
end

test "clear_list_backends_cache/1 refreshes cached source backends", %{
backend: backend,
source: source
} do
backend_id = backend.id

# Prime the cache with the backend currently associated with the source.
assert [%{id: ^backend_id}] = Backends.Cache.list_backends(source_id: source.id)

# Remove the association directly so the cached result remains stale.
assert {1, nil} =
Repo.delete_all(
from(sb in "sources_backends",
where: sb.source_id == ^source.id and sb.backend_id == ^backend.id
)
)

assert [%{id: ^backend_id}] = Backends.Cache.list_backends(source_id: source.id)

# Clearing the source-specific entry makes the next lookup reflect the database.
assert :ok = Backends.clear_list_backends_cache(source.id)
assert [] = Backends.Cache.list_backends(source_id: source.id)
end

test "warmer", %{user: user} do
assert {:ok, []} = CacheWarmer.execute(nil)

Expand Down
Loading