Skip to content

Commit 11e963b

Browse files
committed
fix: bump to 0.3.10 for sandbox fix for smembers & sadd
1 parent f64f8ea commit 11e963b

File tree

5 files changed

+26
-94
lines changed

5 files changed

+26
-94
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.3.10
2+
- fix: sandbox fix for smembers & sadd
3+
14
# 0.3.9
25
- chore: add docs
36
- fix: set fix

guides/how-to/testing_with_cache.md

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -97,85 +97,6 @@ defmodule MyApp.CacheTest do
9797
end
9898
```
9999

100-
## Testing with Multiple Cache Modules
101-
102-
If your application uses multiple cache modules, register each one with the sandbox:
103-
104-
```elixir
105-
setup do
106-
sandbox_id = "test-#{:erlang.unique_integer([:positive])}"
107-
108-
:ok = Cache.SandboxRegistry.register(MyApp.UserCache, sandbox_id)
109-
:ok = Cache.SandboxRegistry.register(MyApp.SessionCache, sandbox_id)
110-
111-
on_exit(fn ->
112-
Cache.SandboxRegistry.unregister(MyApp.UserCache)
113-
Cache.SandboxRegistry.unregister(MyApp.SessionCache)
114-
end)
115-
116-
:ok
117-
end
118-
```
119-
120-
## Testing Asynchronously
121-
122-
The sandbox functionality allows for safe asynchronous testing:
123-
124-
```elixir
125-
defmodule MyApp.AsyncCacheTest do
126-
use ExUnit.Case, async: true
127-
128-
setup do
129-
sandbox_id = "test-#{:erlang.unique_integer([:positive])}"
130-
:ok = Cache.SandboxRegistry.register(MyApp.Cache, sandbox_id)
131-
132-
on_exit(fn ->
133-
Cache.SandboxRegistry.unregister(MyApp.Cache)
134-
end)
135-
136-
:ok
137-
end
138-
139-
# Tests run in parallel without interfering with each other
140-
test "first test" do
141-
assert :ok = MyApp.Cache.put("key-1", "value-1")
142-
assert {:ok, "value-1"} = MyApp.Cache.get("key-1")
143-
assert {:ok, nil} = MyApp.Cache.get("key-2") # Doesn't see other test's data
144-
end
145-
146-
test "second test" do
147-
assert :ok = MyApp.Cache.put("key-2", "value-2")
148-
assert {:ok, "value-2"} = MyApp.Cache.get("key-2")
149-
assert {:ok, nil} = MyApp.Cache.get("key-1") # Doesn't see other test's data
150-
end
151-
end
152-
```
153-
154-
## Mocking Cache Interactions
155-
156-
For unit tests where you want to mock the cache entirely:
157-
158-
```elixir
159-
defmodule MyApp.ServiceTest do
160-
use ExUnit.Case
161-
import Mox
162-
163-
# Define a mock for your cache
164-
defmock(MockCache, for: MyApp.CacheBehaviour)
165-
166-
setup :verify_on_exit!
167-
168-
test "service uses cache correctly" do
169-
# Set up expectations for the mock
170-
expect(MockCache, :get, fn "user:1" -> {:ok, %{name: "Test User"}} end)
171-
expect(MockCache, :put, fn "user:1", _ttl, _data -> :ok end)
172-
173-
# Test your service that uses the cache
174-
result = MyApp.Service.update_user(1, %{name: "Updated User"})
175-
assert result == :ok
176-
end
177-
end
178-
```
179100

180101
## Tips for Testing with ElixirCache
181102

lib/cache/redis.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ defmodule Cache.Redis do
2424

2525
@moduledoc """
2626
Redis adapter for distributed caching with ElixirCache.
27-
27+
2828
This adapter provides a connection pool to Redis, enabling distributed caching
2929
across multiple nodes or services. It supports the standard Cache behavior plus
3030
additional Redis-specific operations like hash manipulation, JSON operations, and sets.
31-
31+
3232
## Features
33-
33+
3434
* Connection pooling for efficient Redis access
3535
* Support for Redis URI connection strings
3636
* Hash operations for storing field-value pairs within a key
3737
* JSON operations for working with complex nested data structures
3838
* Set operations for managing collections
3939
* Direct access to Redis commands via pipeline and command functions
40-
40+
4141
## Options
4242
#{NimbleOptions.docs(@opts_definition)}
43-
43+
4444
## Example
45-
45+
4646
```elixir
4747
defmodule MyApp.RedisCache do
4848
use Cache,

lib/cache/sandbox.ex

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
defmodule Cache.Sandbox do
22
@moduledoc """
33
Sandbox adapter for isolated testing of applications using ElixirCache.
4-
4+
55
This module provides a mock implementation of all cache adapters, allowing tests to run in isolation
66
without interfering with each other's data. The sandbox uses a basic `Agent` to store data in memory
77
and implements the full range of caching operations supported by all adapters.
8-
8+
99
## Features
10-
10+
1111
* Isolated cache namespaces for concurrent testing
1212
* Support for all standard cache operations
1313
* Implementation of Redis-specific features like hash and JSON operations
1414
* Implementation of ETS-specific operations for complete testing compatibility
1515
* Lightweight in-memory storage for fast test execution
16-
16+
1717
## Usage
18-
18+
1919
The Sandbox adapter is typically enabled through the `sandbox?` option when defining a cache module:
20-
20+
2121
```elixir
2222
defmodule MyApp.TestCache do
2323
use Cache,
@@ -27,10 +27,10 @@ defmodule Cache.Sandbox do
2727
sandbox?: Mix.env() == :test
2828
end
2929
```
30-
30+
3131
In your tests, use `Cache.SandboxRegistry.start(MyApp.TestCache)` in the setup block to ensure
3232
proper isolation between test cases.
33-
33+
3434
> **Note**: This adapter should not be used in production environments.
3535
"""
3636

@@ -333,6 +333,14 @@ defmodule Cache.Sandbox do
333333
raise "Not Implemented"
334334
end
335335

336+
def smembers(_cache_name, _key, _opts \\ []) do
337+
raise "Not Implemented"
338+
end
339+
340+
def sadd(_cache_name, _key, _value, _opts \\ []) do
341+
raise "Not Implemented"
342+
end
343+
336344
defp put_hash_field_values(state, key, fields_values) do
337345
Map.update(
338346
state,

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule ElixirCache.MixProject do
44
def project do
55
[
66
app: :elixir_cache,
7-
version: "0.3.9",
7+
version: "0.3.10",
88
elixir: "~> 1.11",
99
start_permanent: Mix.env() == :prod,
1010
description: "Standardized and testable caching across your app. In test caches are isolated.",

0 commit comments

Comments
 (0)