简体   繁体   中英

How do I test if Rack::Cache is functioning with Sinatra app on Heroku with memcache?

I'm making a web app where many users will be viewing a Google map, with updates on the map pulled in through ajax requests to the server. I want the response that is sent to the users to be cached, because it involves scraping data from an outside server, and it only needs to update every 2-3 minutes.

So, as soon as one person requests the data, I want all subsequent requests from all other users to be pulled in from the cache for the next 2-3 minutes. I followed this tutorial , which details how to set up Rack::Cache and the Dalli gem in Sinatra with Heroku, and when I ran a test on a page set up with the following,

cache_control :public, max_age: 3000

I can see the cache headers come through correctly (using Google Chrome Developer Tools), but if I hit refresh, or if I request the page from another computer, the content was clearly regenerated (I put a Time.now output). However, if I go to another page, then retype the URL, the content is not regenerated. I think the browser is caching the result, but not the memcache server? Do I have a fundamental misunderstanding of how caching works?

For people who come upon this question, here are some threads which may help you solve your issue (helped me).

"refresh" in your browser, causes a "Cache-Control: max-age=0": https://groups.google.com/forum/#!topic/rack-cache/sWHyu4pYwKw

Clearing cache and removing cache directory (this worked for me): https://github.com/rails/rails/issues/5245

Adding specs for it with rspec / other Sinatra, Rack::Test, and Conditional GET requests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM