S3Cache ======= Created by Steve Odom (steve.odom@gmail.com) License: GPL DEPENDENCIES: Amazon s3 Library for REST in Ruby (included as s3.rb) http://developer.amazonwebservices.com/connect/entry.jspa?externalID=135&categoryID=47 Background: S3Cache creates a new fragment cache filestore using Amazon's Simple Storage Service (S3). Instead of your fragment caches stored at say "#{RAILS_ROOT}/cache", your cache can now be located at one of your S3 buckets. For more information on S3, goto: http://www.amazon.com/gp/browse.html?node=16427261 S3Cache also extends ActionView Helpers by adding a new cache helper called "cache_xml". This caches xml and rss files at S3. Your rss feed can then be accessed at something like http://steveodom.s3.amazonaws.com/feeds/my_feed.rss. My main goal is writing this plugin was to offload my xml and rss feeds to S3. For fragments within one of your existing rails pages, there is definitely a performance consideration for caching your fragments at S3 instead of your own server. It is just not as fast passing bits over the internet as it is keeping it all on your own server. Having said that, I have found the performance of my rails pages with cached fragments stored at S3 to be acceptable. It is a little slower, but not so much where most site visitors will even know the difference. Get Plugin: Check out as a plugin from inside your app directory ruby script/plugin install -x http://s3cachestore.googlecode.com/svn/trunk/plugins/s3cache Use: 1. Get an account at S3 and create a bucket where the cached files will be stored. I recommend the Firefox plugin S3 Organizer. It makes it dead simple to create buckets. Find it here: https://addons.mozilla.org/firefox/3247/ 2. In the S3Cache.rb file, copy in your own Amazon access key, secret access key and your bucket name. 3. You also need to make sure you have caching turned on by having this line in development.rb or production.rb set to true: config.action_controller.perform_caching = true At this point, if you have already been using fragment caching in your application, you don't have to do anything else. Your fragments will now be written to and served from S3. If you have not implemented fragment caching then some good resources are: Book: Agile Web Development with Rails Rails API: http://api.rubyonrails.com/classes/ActionController/Caching/Fragments.html Presentation: http://scottstuff.net/presentations/rails-caching/ 4. To cache an rss or xml file, your rxml file should look something like: cache_xml(:action => 'show', :id => @question.id) do xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.question do xml.text @question.question_text end end Then make sure the link you give users is the S3 link and not your regular rails rss link. For example, your rss feed link can be something like: http://yourbucketname.s3.amazonaws.com/cache/yourdomain.com/questions/show.xml. 5. Expire your fragments as you normally would.