views:

175

answers:

2

I am looking for a simple and automated way to store the page cache on S3 (and of course cloudfront.) I know of a plugin that does this with the fragment cache, but before I create it myself, wanted to tap into the collective wisdom here :)

Edited: To make myself more clear, I am not looking to use S3 to serve the files, but rather, the CloudFront CDN.

A: 

I read the headline and was going to tell you Amazon started doing a CDN a few weeks back. But obviously, you already know that. :)

There's a Python package that looks like it wraps CloudFront, botto. But that's all I can find.

I think you're the first... go forth and start it. Let me know where it is, I'll probably fork it.

Otto
+2  A: 

In order to put something in CloudFront, you have to first have it in S3. See Amazon's introduction for all the steps. Basically, you put the document in a bucket on S3 and then make an API call to register your bucket for distribution (you do this using a perl script they provide). At that point, they transfer the contents of your bucket out to the edge servers for high performance distribution. You can change the contents of your bucket once an hour.

Anyway, in order to use CloudFront, what you really need to do is get the contents of your rendered pages into S3. Once you've gotten your distribution up and running this is how you manage your content in CloudFront.

The simplest way to manage a cache in S3 would probably be to create a model for your cache and use the attachment_fu plugin to store the page contents in s3. Then, you could use ActiveRecord's Observer functionality to invalidate and re-populate the cache as appropriate for your application. The only other tricky bit would be reaching into ActionView to access the result of rendering a page, but I bet you could crib some of that code from the default page caching system itself.

If you really wanted to, you could probably wrap all of this functionality up into a plugin that would make it easy to re-use across applications for you and others.

Greg Borenstein