schwarz

archive of mindset

schwarz header image 3

OpenURI and MemCached sitting in a tree

Tue Jan 15 01:39:00 UTC 2008 · 2 comments

The ultimate frankenstein-like experiment of harnessing OpenURI and MemCached has been completed!

For a number of projects that used openuri, I needed a way to reduce hits on remote services or rest apis, or even speed up the experience on the client end.

Getting it

sudo gem install openuri_memcached

The beast is alive! (Usage, for those not on late hours right now)

Use exactly the same as you would openuri, only.. enable it.

  require 'openuri_memcached'
  OpenURI::Cache.enable!
  open("http://germanforblack.com").read # Slow as a wet week

Quit your app (leave memcached running) and run the same example, it should now happen in less then … some time that is really fast.

Small print options

To get started run your memcached server

$ memcached -d

The default address that this gem will terminate against is localhost:11211, you can change this using:

OpenURI::Cache.host = ['serverone.com:11211', 'servertwo:11211']

The cache defaults to 15 minutes, however this can be changed using:

OpenURI::Cache.expiry = 60 * 10 # Ten long minutes

Let me know if you have any issues with it, or if you have any use for it!

Tags:······

  • 1 Marcus Crafter // Jan 20, 2008 at 06:44 PM

    Very cool mate, looking forward to using this in upcoming apps. Well done :)
  • 2 Eivind Uggedal // Apr 12, 2008 at 06:59 AM

    My spec runs went from 50sec to 4.5sec on a http scraping app I'm working on. Thanks!