public
Description: Everything-agnostic, pluggable-backend, threadsafe, lightweight Ruby cache interface library
Clone URL: git://github.com/mmcgrana/keyed.git
keyed /
name age message
file README.textile Fri Aug 08 15:44:19 -0700 2008 fix README typo [mmcgrana]
file TODO.textile Thu Jul 24 06:51:53 -0700 2008 first commit [mmcgrana]
file keyed.gemspec Thu Jul 24 06:51:53 -0700 2008 first commit [mmcgrana]
directory lib/ Thu Jul 24 06:51:53 -0700 2008 first commit [mmcgrana]
directory spec/ Thu Jul 24 06:51:53 -0700 2008 first commit [mmcgrana]
README.textile

Keyed

Everything-agnostic, pluggable-backend, threadsafe, lightweight Ruby cache interface library

Usage


  cache = 
    Keyed::MemoryStore.new, 
  # Keyed::FileStore.new(:cache_dir => "/tmp/my_cache")
  # Keyed::MemcachedStore.new(:host => "127.0.0.1:11211")
  => #<Keyed::MemoryStore:0x8bd44 @hash={} @mutex=#<Mutex:0x87708>>

  cache.get("foo")         
  => nil

  cache.set("foo", "foo-cached")
  => "bar" 

  cache.get("foo")
  => "foo-cached" 

  cache.fetch("bar") { puts "caching"; "bar-cached"}
  caching
  => "bar-cached" 

  cache.fetch("bar") { puts "caching"; "bar-cached" }
  => "bar-cached" 

  cache.expire("bar")
  cache.get("bar")
  => nil

  cache.expire_all
  cache.get("foo")
  => nil

The initializers for the cache store classes are documented in their respective class files.

The instance methods to manipulate the resulting classes are all documented in abstract_store.rb.

Threadsaftey

Multiple threads can share a single keyed cache instance. Each stores use different mechanism to handle concurrency: the MemoryStore uses a mutex, the FileStore uses file locks, and the MemcachedStore uses a shared pool of single-threaded Memcached instances.

Dependencies

Keyed::MemcachedStore requires the memcached gem and connection_pool library, the other stores have no dependencies.