Cache Plugin Proposal
The Cache plugin sets the Expired Header of the referenced file responce to a date 21 years in the future. It does this by changing the URL of the link. When the browser makes a request for the referenced file at the new location a servlet returns the file but with a Expire Header set to the date in the future. Most browsers will then not bother making a new request for that file again, greatly improving the page loading time of your grails application. When you modify the file, then the cache plugin will modify URl automaticly.
Advantages
- Because the browser never needs to make a 2nd request the Cache Plugin decreases page loading times.
- It reduces the number of request to the server and therefore because most browsers do not Pipeline requests it saves on latency of loading the page.
- It reduces bandwidth requirements on both the server and browser.
- It reduces server load and therefore you can use a lower spec server, and save the environment
- No configuration of a server is needed
To use the Plugin
Install the plugin, and then when you want an object cached on a page just use the tag <g:cacheLinkTo dir="images" file="logo.jpg" />. The plugin takes care of the rest.
How it works
The tag library translates the tag <g:cacheLinkTo dir="images" file="logo.jpg" /> into a link that references a directory called your_app/cache/5TsTs33eD/images/logo.jpg. Where 5TsTs33eD is Base64 encoding of the last modified date of the file logo.jpg. When the browser makes the request for your_app/cache/5TsTs33eD/images/logo.jpg the cache servlet returns the file normally but with the Expires header set to the future. If you modify the file then when the main page (the page with the link on it) is requested again it will return a link to a new directory as last modified date of the file is changed. I.e your_app/cache/5TsTs33eD/images/logo.jpg becomes your_app/cache/AAs3edF4D/images/logo.jpg and the browser will believe that it is requesting a new file.
Further Work
The second stage will be make grails behave with Edge Server Caches. Wikimedia, and Plone have managed to get their performance from very slow to reasonable speeds by integrating with Edge Severs (Such a Squid as a Transparent proxy). I hope that we will be able to make grails lightning fast by doing this.
James Page