Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

Rails cache not works - redis automatically detects database change?

$
0
0

I'm using graphql for my rails api. And use redis for cache store.

In a graphql query, I'm using cache to optimize performance:

graphql/types/query_type.rb

field :labels, [Types::LabelType], null: false do  description 'Get all food labels'enddef labels  Rails.cache.fetch("labels", expires_in: 24.hours) do    Label.all  endend

10 labels are seeded in the database and when I test query in localhost:3000/graphiql, it shows 10 results correctly. However, if I delete a row manually in the database, it returns 9 records instead of cached 10 results.

Here is my environment configuration:

config/environments/development.rb

if Rails.root.join('tmp', 'caching-dev.txt').exist?  config.action_controller.perform_caching = true  config.cache_store = :redis_cache_store, { url: ENV.fetch("REDIS_URL_CACHING", "redis://localhost:6379/0") }  config.public_file_server.headers = {'Cache-Control' => "public, max-age=#{2.days.to_i}"  }else  config.action_controller.perform_caching = false  config.cache_store = :null_storeend

I ran rails dev:cache and there is caching-dev.txt in tmp directory.What am I missing here?


Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>