in response to #9: #10

Merged
merged 2 commits into from Dec 10, 2011

Projects

None yet

2 participants

@kellyredding
Owner
  • respond to the request even if the file has been cached.

/cc @fnordfish

@kellyredding in response to #9:
* respond to the request even if the file has been cached.
e11f9c4
@kellyredding
Owner

@fnordfish - How about doing something like this instead. Doing this, rack-less won't ignore the request if there is a file already cached. Try this branch out with config.cache = true and let me know if it works for your use case.

@kellyredding Also need to make the source object always overwrite the file when ca…
…ching

* don't care if the file already exists or not
* if the request makes it this far then rack-less needs to update the cached file regardless
d2a0841
@kellyredding
Owner

@fnordfish - forgot to make the source object also not care whether a file had already been cached. Added in your test from #9 to verify.

Basically, I'd rather just have rack-less always force write cache if you tell it to, rather than add in an additional option for the users to deal with. Make sense?

@fnordfish

@kelredd - That would be a large breaking change for all apps actually using cached files at the moment.
The caching feature makes absolute sense. I didn't want to drop it, nor change any of the current behavior for existing applications (or rack-less).
I'd rather liked the app to decide, whether the cached files will be updated. In my case this would be the environment the app is running in. Other people may find their own triggers for telling rack-less to update a particular file.

@fnordfish

On the other hand, could we make a poll who really uses rack-less in an production environment ;)

@kellyredding
Owner

@fnordfish - I'm not sure how it breaks all apps. In my use of cached files (only in production environments), once I cache a file (to public/stylesheets for example), any subsequent requests to the file never make it to the rack-less middleware. The webserver sees a static file and serves it directly.

Actually, rack-less was kind of broken (in a sense) the way it was before. With those 'already cached' checks in place, if you had a cached file and the request actually made it to the middleware (meaning you webserver didn't serve the cached file directly), rack-less would ignore the request and pass it on up the stack. That really isn't good. Whether you already have a file cached or not, rack-less should respond to appropriate requests and generate the source for that request.

re: "I'd rather liked the app to decide, whether the cached files will be updated". You can achieve this without an additional config option. If you want the cached files updated on every request, have your webserver ignore them (or don't use Rack::Static or whatever). If you don't want the cached files updated on every request, have your webserver serve any cached files if they exist (or use Rack::Static or whatever). Does that make sense? Am I missing a scenario?

Does this fix work in your scenario from #9?

@fnordfish

@kelredd - Yes, works for me.
I see your point, you're right. This really should be handled before it hit any middleware in production environments.

@kellyredding
Owner

@fnordfish excellent - glad it works. Thanks for putting in the extra test assertions in #9 (that I shamelessly copied here) - that really helped validate the concept.

I'll merge this, close #9 and roll a new version shortly.

@kellyredding kellyredding merged commit d2b8b15 into master Dec 10, 2011
@kellyredding kellyredding added a commit that referenced this pull request Dec 10, 2011
@kellyredding version to v3.0.2
* better cache behavior (#10/#9)
* when caching, rack-less will always respond and re-cache (whether a cached file for the request exists or not)
56d8770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment