Is your plugin hosted on GitHub? Make sure to press the "fetch" button next to the repository field to fetch your plugin's info from GitHub rather than typing it all in.
Repository
Name
Home Page
Short description This plugin overrides cache and cache_erb_fragment, inserting an HTML comment into the beginning of the block of HTML being cached. The plugin reads this HTML comment and expires cache fragments that are older than their TTL.
Description *Problem:* You're enjoying the performance benefits of fragment caching, but managing the cache using sweepers is not really appropriate for some fragments. Instead, you'd rather have a "time to live" option for a cached fragment, so that the cache would be expired and the fragment regenerated only if it has passed a certain age. *Solution:* Of course, there are many ways to skin this cat. In the end, I settled on somewhat of a hack. However, this solution will work no matter what storage option you are using for caching. Basically, the plugin overrides _cache_ and _cache_erb_fragment_, inserting an HTML comment into the beginning of the block of HTML being cached. This HTML comment contains a timestamp (using the _to_i_ method on a Ruby _Time_ object) which marks the time (in UTC) at which the fragment expires. The next time _cache_ is called, the fragment gets read, the timestamp can be checked, and the fragment can be expired or preserved depending on the current time. *Examples* In a view: <pre> <% cache("some_fragment", :time_to_live => 5.minutes) do -%> This fragment was cached at <%= Time.now.utc.strftime "%H:%M:%S on %m/%d/%Y" %> and will expire at: <%= 5.minutes.from_now.utc.strftime "%H:%M:%S on %m/%d/%Y" %> (UTC) <% end %> </pre> In a controller: <pre> # instead of: read_fragment("some_fragment"), try: unless get_johnny_cache("some_fragment") # make some expensive DB queries end </pre> h3. Installation <pre> script/plugin install http://svn.offtheline.net/plugins/johnny_cache/ </pre> (or use piston or whatever you prefer) *Notes* * *Remember:* If you want to play with caching and you're working in the *development* environment, you need to enable caching. Find the perform_caching line in environments/development.rb and change it to true, and restart your server. If you don't make this change, you're never caching any fragments, and therefore, this plugin won't do anything for you (in development; caching is turned on by default for the production environment). * Works in Rails 2.0.2 and the example also works in Rails 2.1.0; however, the tests I wrote for the plugin only work in Rails 2.0.2. Apparently they changed something about the way you test ERB in 2.1.0 and I haven't had a chance to figure out what's wrong. * I assume this only works for ERB fragment caching and not Haml (or any other HTML generator). However, the code for the plugin is pretty simple and it should be easy to adapt it to Haml if you desire.
Description format RDoc MarkDown Textile
License Ruby's Rails' (MIT) GPL LGPL BSD Apache Artistic PublicDomain BSD-type Free-Trial Free-but-Restricted OpenSource Proprietary Shareware Source-available-proprietary Commercial
Category Assets Controllers Internationalization Misc. Enhancements Model Rails Engines Searching and Queries Security Statistics and Logs Testing View Extensions