-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging? #22
Comments
Note that I'm sure that the issue is in my code, but having logs would help with debugging my issue. |
You can make use of ActiveSupport::Notifications for logging and debugging. Something like this should do it: ActiveSupport::Notifications.subscribe(/cache*+active_support/) do |name, start, finish, id, payload|
Rails.logger.debug ['cache:', name, finish - start, id, payload].join(' ')
end |
Thanks for that tip. I dug into the issue a bit more, and I think I found a bug in how I construct my cache like so: @cache_store = Readthis::Cache.new(
redis: { url: ENV['REDIS_CACHE_URL'], driver: :hiredis },
marshal: Oj
)
@cache_store.options[:namespace] = "Admin::Campaign" I know the So even though the @cache_store
=> #<Readthis::Cache:0x00000111325458
@entity=#<Readthis::Entity:0x000001113247b0 @compression=false, @marshal=Oj, @threshold=1024>,
@expires_in=nil,
@namespace=nil,
@options={:redis=>{:url=>"redis://redacted:1234", :driver=>:hiredis}, :marshal=>Oj, :namespace=>Admin::Campaign},
@pool=...
@cache_store.instance_variable_get :@namespace
=> nil See how ActiveSupport::Cache::Store#namespaced_key checks the I can see why you'd want to omit this for the sake of performance (in which case I'd recommend |
Good find. The |
It turns out that this makes it faster for some operations.
With merge:
|
Thanks for the fast turnaround. Can you issue a patch-level gem version bump? |
I'd prefer to wait and get some usage from master before I bump the patch version. If you've given it a run please report back here. |
I just encountered a different (unrelated error): r = Readthis::Cache.new(
redis: { url: ENV['REDIS_CACHE_URL'], driver: :hiredis },
marshal: Oj
)
r.options[:namespace] = "Admin::Campaigns"
r.write :all, []
# =>
TypeError: no implicit conversion of nil into Integer
from /Users/chris/.rvm/gems/ruby-2.1.3@the_app/bundler/gems/readthis-84aaaf569337/lib/readthis/entity.rb:95:in `pack' Can you reproduce? |
If you are using master with Oj you will need to configure Oj as one of the possible loaders. That can probably use a better error though, I'll set something up. |
It is easy to forget to set up a custom serializer, and the resulting error is extremely obscure. The serializer's `assoc` and `rassoc` methods now raise a more helpful `UnknownSerializerError` for any missing serializer or corresponding flag. Closes #22
Thanks for the responsiveness. I think I have another issue for you (sorry), or at least my understanding is lacking: Configuring the cache as per my previous example (added "\u0004{\"^o\":\"Admin::Campaign\",\"id\":\"1\"}" Compare that to just "{\"^o\":\"Admin::Campaign\",\"id\":\"1\"}" This difference is obviously the Upon further investigation, I'm probably wrong, since doing Unrelated issue: Readthis.serializers << Oj
=> #<Readthis::Serializers:0x007f8c70a2a518 @inverted={1=>Marshal, 2=>Readthis::Passthrough, 3=>JSON, 5=>Oj}, @serializers={Marshal=>1, Readthis::Passthrough=>2, JSON=>3, Oj=>5}>
# try to read from cache =>
Readthis::UnknownSerializerError: '0' doesn't match any serializers
from .../lib/readthis/serializers.rb:95:in `rassoc' |
The |
@sorentwo I appreciate your support throughout this, and I'm sorry to pester you with another issue, but I'm seeing incorrect deserialization on # using pry within #write_entity
> store.set(namespaced, dumped)
=> "OK"
> value = store.get(namespaced_key(key, merged_options(options)))
=> "\u0004{\"^o\":\"Admin::Campaign\",\"id\":\"1\"}"
> entity.load(value)
=> "\u0004{\"^o\":\"Admin::Campaign\",\"id\":\"1\"}" I would expect this to be deserialized back into a |
To add to my above comment, I dug further, and it looks as though within > marshal = serializers.rassoc(flags & MARSHAL_FLAG) # flags => 4
=> nil Therefore, back in ...
rescue TypeError, NoMethodError
string
end Can you have a look when you have a moment? |
@findchris Thanks for digging around. I broke the build in a crucial spot earlier today, which you also happened to discover. I've removed the strict error that was triggered within the |
Hi again @sorentwo - The issue as described in the comment above (#22 (comment)) is still occurring (and I'm running on the latest from master [61c969c]). |
Another follow up on my investigation @sorentwo... The setup ( > flags
=> 4
> serializers.instance_variable_get :@inverted
=> {1=>Marshal, 2=>Readthis::Passthrough, 3=>JSON, 4=>Oj} It seems that within > marshal = serializers.rassoc(flags & MARSHAL_FLAG)
=> nil # because flags & MARSHAL_FLAG returns 0 to > marshal = serializers.rassoc(flags)
=> Oj All works as planned. Any insight here? |
Could it be an inconsistency between: BASE_SERIALIZERS = {
Marshal => 0x1,
Passthrough => 0x2,
JSON => 0x3
}.freeze and MARSHAL_FLAG = 0x3 ? |
@findchris: Thanks for putting so much effort into tracking this down! Your discovery about the |
Cool; I'll check it out. Regenerate |
I've tested this out, and all is working for me now 👍 |
FYI, I deployed this to production earlier today, and I am noticing a small decrease in CPU/latency, most likely due to leveraging Anyway, nice work on the gem, and please do continue your support of it 👍 |
Thanks @findchris! You really helped drive these latest releases to a stable place. |
@sorentwo 👌 I'm locked to the current commit, so I'll look forward to a gem release. |
Hi there.
I'm switching to
readthis
fromredis_store
, and am seeing unexpected cache keys being written. In trying to debug this, I was looking for logging of some sort: Observing which keys and values are being written or read per operation. Am I overlooking existing functionality, or might this be something you'd support?Cheers.
The text was updated successfully, but these errors were encountered: