phillc / klarlack forked from schoefmax/klarlack

klarlack is a ruby client library for the varnish administration interface. It allows, among other things, purging of cached objects from ruby code.

This URL has Read+Write access

phillc (author)
Fri Nov 06 09:05:11 -0800 2009
commit  868e761b603b9fc42ef92e98ea12b5d94b8f4734
tree    69057d82f1b16a64d4d4de6d80fb4a3e6632e6a7
parent  21316f28382ef3c862274aa229f4720110201690
name age message
file .document Fri Apr 03 12:07:45 -0700 2009 Initial commit to klarlack. [schoefmax]
file .gitignore Fri Apr 03 12:07:45 -0700 2009 Initial commit to klarlack. [schoefmax]
file LICENSE Fri Apr 03 12:07:45 -0700 2009 Initial commit to klarlack. [schoefmax]
file README.rdoc Loading commit data...
file Rakefile Thu Apr 23 05:54:41 -0700 2009 first commit [schoefmax]
file VERSION.yml
file klarlack.gemspec
directory lib/
directory recipes/
directory spec/
directory tasks/
README.rdoc

klarlack

Klarlack is a ruby client library for the varnish administration interface.

See also: www.varnish-cache.org

Please note: You need at least version 2.0.3 of varnish for purging to work.

Installation

  sudo gem install schoefmax-klarlack --source=http://gems.github.com

Example

Lets purge all blog posts from the cache…

  require 'rubygems'
  require 'klarlack'

  varnish = Varnish::Client.new '127.0.0.1:6082'
  # the regexp is not a ruby regexp, just a plain string varnishd understands
  varnish.purge :url, "^/posts/.*"

In a Rails app, you might want to use use this in a cache sweeper.

Specs

Start up a local varnishd with -T 127.0.0.1:6082. Then run

  spec spec

TODO

  • Support authentication when varnishd is started with -S
  • Make parameter manipulation/display more friendly

WTF?

dict.leo.org/?search=klarlack

MClient

config/varnish.yml

  development:
    cache1:
      port: 6082
      host: localhost
  test:
    cache1:
      port: 6082
      host: localhost
  production:
    cache1:
      port: 6082
      host: localhost
    cache2:
      port: 6083
      host: 127.0.0.1

Lets purge all blog posts from all cache servers…

  require 'rubygems'
  require 'klarlack'

  >> varnish = Varnish::MClient.new
  => #<Varnish::MClient:0x26c9fc4 @config={:cache2=>{"port"=>6083, "host"=>"127.0.0.1"}, :cache1=>{"port"=>6082, "host"=>"localhost"}}, @servers={:cache2=>#<Varnish::Client:0x26c0668 @keep_alive=false, @timeout=1, @mutex=#<Mutex:0x26c0564>, @port=6083, @host="127.0.0.1">, :cache1=>#<Varnish::Client:0x26c04c4 @keep_alive=false, @timeout=1, @mutex=#<Mutex:0x26c03d4>, @port=6082, @host="localhost">}>
  >> varnish.purge :url, "^/posts/.*"
  => {:cache2=>true, :cache1=>true}

Copyright

Copyright © 2009 Max Schöfmann. Distributed under the MIT-License

Modified by Phillip Campbell