crystal-cache / cache Goto Github PK
View Code? Open in Web Editor NEWA key/value store where pairs can expire after a specified interval
License: MIT License
A key/value store where pairs can expire after a specified interval
License: MIT License
from lib/cache/src/cache/stores/redis_store.cr:36:7 in 'read'
Full backtrace:
(Redis::Error)
from lib/redis/src/redis/connection.cr:132:7 in 'receive'
from lib/redis/src/redis/strategy/single_statement.cr:12:5 in 'command'
from lib/redis/src/redis.cr:309:7 in 'command'
from lib/redis/src/redis/command_execution/value_oriented.cr:37:15 in 'string_or_nil_command'
from lib/redis/src/redis/commands.cr:67:7 in 'get'
from lib/cache/src/cache/stores/redis_store.cr:36:7 in 'read'
from src/shards-info.cr:40:7 in '->'
from lib/kemal/src/kemal/route.cr:255:3 in '->'
from lib/kemal/src/kemal/route_handler.cr:255:3 in 'process_request'
from lib/kemal/src/kemal/route_handler.cr:17:7 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/kemal/src/kemal/websocket_handler.cr:13:14 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/kemal/src/kemal/filter_handler.cr:21:7 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/raven/src/raven/integrations/http/handler.cr:44:7 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/kemal/src/kemal/static_file_handler.cr:8:14 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/kemal/src/kemal/exception_handler.cr:8:7 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/kemal/src/kemal/log_handler.cr:8:37 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/handler.cr:26:7 in 'call_next'
from lib/kemal/src/kemal/init_handler.cr:12:7 in 'call'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/request_processor.cr:39:11 in 'process'
from /usr/local/Cellar/crystal/0.30.1/src/http/server/request_processor.cr:16:3 in 'process'
from /usr/local/Cellar/crystal/0.30.1/src/http/server.cr:462:5 in 'handle_client'
from /usr/local/Cellar/crystal/0.30.1/src/http/server.cr:428:13 in '->'
from /usr/local/Cellar/crystal/0.30.1/src/fiber.cr:255:3 in 'run
Shortest reproduction is an extra spec added to the memory_store_spec.cr
specs:
it "with only Int32 as key" do
store = Cache::MemoryStore(Int32, String).new(expires_in: 12.hours)
store.should be_a(Cache::Store(Int32, String))
store.fetch(32) { "bar" }
store.fetch(1) { "baz" }
store.keys.should eq(Set{32, 1})
store.read(32).should eq("bar")
store.read(1).should eq("baz")
end
Causes compiler error:
In src/cache/store.cr:71:9
71 | read_impl(key)
^--------
Error: no overload matches 'Cache::MemoryStore(Int32, String)#read_impl' with type (Int32 | String)
Overloads are:
- Cache::MemoryStore(K, V)#read_impl(key : K)
Couldn't find overloads for these types:
- Cache::MemoryStore(Int32, String)#read_impl(key : String)
Looks like the namespace_key
always converts the type of the passed in key to the fetch
method to a union type of String | K
. If K
isn't already a union type including String
, it causes the above error.
Crystal 1.6 changed how types overloads are considered, which I guess is why this became a problem now. Workaround for the time being is to make the key type a union including String
.
Hi, Anton!
Maybe I didn't understand something but compress option raise error after compress disabled.
require "cache"
INSTANCE = Cache::MemoryStore(String, Hash(String, String)).new(expires_in: 30.seconds, compress: false)
data = {
"a" => 1,
"b" => "bla"
}
result = INSTANCE.fetch("data_key") do
data
end
pp result
In lib/cache/src/cache/stores/memory_store.cr:35:33
35 | Cache::DataCompressor.inflate(entry.value)
^------
Error: no overload matches 'Cache::DataCompressor.inflate' with type Hash(String, String)
Overloads are:
- Cache::DataCompressor#inflate(data : String)
Compress data before saving to cache to reduce memory usage.
Because of this line in def fetch
in stores:
def fetch(key : K, *, expires_in = @expires_in, &block)
value = read(key)
return value if value # <--
false values are not being returned from cache even though they are written to it.
Is this intentional or the if value
should be improved to allow false?
Memcached is currently the most popular cache store for production websites.
I will not implement this because I don't use Memcached.
So if you have some experience with Memcached and want to contribute to an open source project, don't delay! ❤️
This option can be used to create a namespace within the cache store.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.