kematzy / sinatra-cache

A Sinatra Extension that makes Page and Fragment Caching easy
MIT License
161 stars 21 forks source link

cache is generated but not used #4

Closed dentarg closed 14 years ago

dentarg commented 14 years ago

I'm trying to use sinatra-cache for a project. I have a method (http://github.com/Starkast/starkast.net/blob/master/starkast.rb#L49) that takes very long time (around 20 seconds) to execute (because it's talking to flickr a lot).

public/ is populated with generated cache files (*.html) which loads much faster if you access them directly (append .html to the ordinary URL), but they don't seem to be used at all when accessing the ordinary URL. Shouldn't they?

(Compare http://starkast.net/arvika2010.html to http://starkast.net/arvika2010 for example)

Have I misunderstood something about how sinatra-cache works?

(Haven't been able to use the :cache_logging to investigate because of kematzy/sinatra-logger#1)

kematzy commented 14 years ago

Hejsan svejsan Dentarg,

No I don't think you have misunderstood how Sinatra::Cache works. I think the problem is with how your server and URLs are setup.

Your cached HTML file is NOT being picked up by the server, and instead it loads the page through Sinatra. I would suggest using something like a .htaccess (mod_write) instructions to look for the the .HTML file first and if not found then pass the request to Sinatra.

While on this topic, it's generally better to have your URLs ending in a '/' [slash], so that they become cached as [ /arvika2010/index.html ] instead. This for some reason easier for a web server to pick up.

Hope that helps you.