You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-6Lines changed: 75 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
-
# LuckyCacheRedisStore
1
+
# LuckyCache Redis Store
2
2
3
-
An adapter for [LuckyCache](https://github.com/luckyframework/lucky_cache/) to store
4
-
data in Redis.
3
+
A Redis storage backend for [LuckyCache](https://github.com/luckyframework/lucky_cache/), providing distributed caching capabilities for Lucky Framework applications.
5
4
6
5
## Installation
7
6
@@ -20,14 +19,84 @@ data in Redis.
20
19
## Usage
21
20
22
21
```crystal
22
+
require "lucky_cache"
23
23
require "lucky_cache_redis_store"
24
+
require "redis"
25
+
26
+
LuckyCache.configure do |settings|
27
+
settings.storage = LuckyCache::RedisStore.new(
28
+
Redis::Client.new(host: "localhost", port: 6379),
29
+
prefix: "myapp:cache:"
30
+
)
31
+
settings.default_duration = 5.minutes
32
+
end
24
33
```
25
34
26
-
TODO: Write usage instructions here
35
+
### Basic Usage
36
+
37
+
```crystal
38
+
cache = LuckyCache.settings.storage
39
+
40
+
# Write to cache
41
+
cache.write("my_key", expires_in: 1.hour) { "my value" }
42
+
43
+
# Read from cache
44
+
if item = cache.read("my_key")
45
+
puts item.value # => "my value"
46
+
end
47
+
48
+
# Fetch (read-through cache)
49
+
value = cache.fetch("computed_key", as: String, expires_in: 10.minutes) do
50
+
# This block is only executed if the key doesn't exist
51
+
expensive_computation
52
+
end
53
+
54
+
# Delete from cache
55
+
cache.delete("my_key")
56
+
57
+
# Clear all cached items with the configured prefix
- Arrays of basic types: `Array(String)`, `Array(Int32)`, `Array(Int64)`, `Array(Float64)`, `Array(Bool)`
66
+
67
+
**Note:** Custom objects that include `LuckyCache::Cachable` are not supported by RedisStore due to serialization limitations. Use MemoryStore for caching custom objects.
68
+
69
+
### Workaround for Custom Objects
70
+
71
+
You can cache JSON representations of your objects:
72
+
73
+
```crystal
74
+
# Instead of caching the object directly
75
+
# cache.write("user:123") { User.new("test@example.com") } # This will raise an error
0 commit comments