schwarz

archive of mindset

schwarz header image 5

OpenURI and MemCached sitting in a tree

January 15, 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!

→ 2 comments Tags:

How to use lighttpd to serve a static site for development

September 18, 2007 · 0 comments

Write the following into your /etc/lighttpd/lighttpd.conf


server.bind = "0.0.0.0"
server.port = 3000
server.document-root = CWD
server.dir-listing = "enable"

mimetype.assign = (  
  ".css"        =>  "text/css",
  ".gif"        =>  "image/gif",
  ".htm"        =>  "text/html",
  ".html"       =>  "text/html",
  ".jpeg"       =>  "image/jpeg",
  ".jpg"        =>  "image/jpeg",
  ".js"         =>  "text/javascript",
  ".png"        =>  "image/png",
  ".swf"        =>  "application/x-shockwave-flash",
  ".txt"        =>  "text/plain"
)

Not bad, now, a really nice way to execute this, would be from the directory of where your sites' html & assets are at.

Place the folowing in to your ~/.bash_login or ~/.profile file.

alias li="lighttpd -D -f /etc/lighttpd/lighttpd.conf"

Proof is in the pudding:


bens-pb:~/sites ben$ li
2007-09-18 23:44:55: (log.c.75) server started

Ctrl+c will quit the server


2007-09-18 23:45:30: (server.c.1216) [note] graceful shutdown started 
2007-09-18 23:45:30: (log.c.135) server stopped

Shazam! Easy.

→ 0 comments Tags: