optimus icon indicating copy to clipboard operation
optimus copied to clipboard

Customise caching for serving live assets

Open antonyshchenko opened this issue 10 years ago • 9 comments

I would like to tweak the way assets are cached by optimus.strategies/serve-live-assets.

It would be nice to have an ability to pass through the options a function that would wrap get-optimized-assets defined in optimus.strategies/serve-live-assets and implement it's own caching.

The reason I need this is that for me serving an uncached assets is slow (page loading takes up to 5 seconds, probably because of several regular expressions in assets definition). TTL caching is not an option for me, because I wan't to see changes instantly when I edit the files. So I decided to implement a strategy with directory watching and cache invalidation when files in directory are changed. So far it's working fine for me, but I had to copy-paste all private functions from optimus.strategies.

antonyshchenko avatar Feb 12 '15 20:02 antonyshchenko

The strategy you have made sounds like an excellent addition to the strategies offered by Optimus, and I would be happy to accept a pull request with the feature.

magnars avatar Feb 12 '15 22:02 magnars

Great! Then I will implement it and submit a PR in a few days.

antonyshchenko avatar Feb 12 '15 22:02 antonyshchenko

:+1:

magnars avatar Feb 12 '15 23:02 magnars

@env0der Hi Anton! Any progress on this?

magnars avatar Apr 12 '15 14:04 magnars

@magnars , could you please take a look at my commit? It's a rough idea (quick hack) that works for me.

How can I get rid of hardcoded "resources" path? Is there a function in optimus that returns a base directory for assets?

Tell me if you like the idea and I will polish the code and write tests.

antonyshchenko avatar Apr 14 '15 20:04 antonyshchenko

Optimus serves assets from the classpath, so the file location is unknown. We do pass in a folder (public most commonly) where the assets are, but these could be coming from anywhere.

To make this work, we'll have to presume that people are serving their assets from a single directory on disk, make resources a default, and add an option to override it. We'll also have to warn people not to use this strategy in production. :)

Thoughts?

magnars avatar Apr 15 '15 04:04 magnars

Any progress? :)

magnars avatar Apr 25 '15 07:04 magnars

Here it is. Sorry for long waiting - I have time for this only during weekends.

antonyshchenko avatar Apr 26 '15 20:04 antonyshchenko

No worries, mate :) Thanks for taking the time!

magnars avatar Apr 27 '15 07:04 magnars