Skip to content
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

cached? and clear methods not working properly? #10

Open
mepatterson opened this issue Aug 4, 2017 · 4 comments
Open

cached? and clear methods not working properly? #10

mepatterson opened this issue Aug 4, 2017 · 4 comments

Comments

@mepatterson
Copy link

I cached a token from my API service:

hash = LockAndCache.lock_and_cache(:api_token, client: client_id) do
  get_token_from_remote
end

After this, it DOES appear to properly cache and not hit the remote service anymore.

but the cached? method doesn't seem to work...

LockAndCache.cached?(:api_token, client: client_id)
=> false

clear doesn't seem to work either

LockAndCache.clear(:api_token, client: client_id)
=> 0

Am I misunderstanding something about usage?

@mepatterson mepatterson changed the title #cached? method not working properly? cached? and clear methods not working properly? Aug 4, 2017
@mepatterson
Copy link
Author

mepatterson commented Aug 4, 2017

Notably, something looks off here with debug mode:

when cache is hit using :api_token, client: client_id...

DEBUG -- : [lock_and_cache] A1 [:api_token] YWE0YTYzOTNiZjAzYzEyMWRkMmE0YTg4YTdmNWMwYjI4YjgwYTFjNw== 7f45b24684191170789c642e3d21c2429de8a0e1

when I try to clear it using :api_token, client: client_id...

DEBUG -- : [lock_and_cache] clear [:api_token, [[:client, "f2a13062e0c7b1ffcff1ecedb029da09f8490940b49f253154b02c2f0a1f4e4e"]]] YTZkNTA0YjY3MDM4ZGZlYWM5YTUyYzdhMWU3NjNjYzlmNmFiZTJlMg== 96b5b2167fef77da21d1052cdda6bd372f42451a

@seamusabshere
Copy link
Owner

hey @mepatterson i just now have time to work on lock_and_cache - sorry for the huge delay. did you figure this out?

@mepatterson
Copy link
Author

I think I just ended up working around it by always hand generating my own key string and not using the clear method. That said, one of the more annoying difficulties we've run into is the need to selectively clear things without doing LockAndCache.flush which flushes the ENTIRE redis cache (even non-lock-and-cache stuff). So the ability to do something like LockAndCache.clear_all or whatever, where it only clears stuff that LockAndCache has put into cache, would be awesome...

@seamusabshere
Copy link
Owner

seamusabshere commented Sep 20, 2018

hey @mepatterson

try putting the lock and cache storage in a different redis db "number"

e.g.

misc_redis = Redis.new db: 1 # non-lock-and-cache stuff
LockAndCache.lock_storage = Redis.new db: 2
LockAndCache.cache_storage = Redis.new db: 3

(updated: put the cache and lock storage in diff dbs themselves, for a total of 3 db numbers used)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants