Rails.cache.exists?(key) is returning false

1.4k Views Asked by At

I have deployed Rails Application on heroku I am using Heroku-redis premium0 addon.

I am checking if key exist in redis then fetch data from redis else call an API, But sometimes Rails.cache.exist?(key) is returning false even when the key exist in the redis, For Example In production.rb

 config.cache_store  = :redis_cache_store
key = "Location_testing123"
if Rails.cache.exists?(key)
   data = Rails.cache.fetch(key)
else
  Rails.logger.info "KEY_NOT_FOUND #{@key},Existing keys are #{Rails.cache.redis.keys}"
  data = call_api
end

But I checked my Heroku logs is showing

2020-07-23T09:30:31.651892+00:00 app[web.1]: I, [2020-07-23T09:30:31.651740 #10]  INFO -- : [bb090357-d9a3-407b-9f76-efbfb1dd1fde] KEY_NOT_FOUND Location_testing123,Existing keys are ["Location_testing120","Location_testing123","Location_testing124", "stat:processed:2020-07-18"]

The above issue is inconsistent, it is happening only sometimes

0

There are 0 best solutions below