class Sprockets::Cache::RiakStore

A simple Riak cache store.

environment.cache = Sprockets::Cache::RiakStore.new($riak)

Public Class Methods

new(riak_client, bucket = "sprockets") click to toggle source
# File lib/sprockets-cache-riak/riak_store.rb, line 11
def initialize(riak_client, bucket = "sprockets")
  @riak   = riak_client
  @bucket = @riak.bucket(bucket)
end

Public Instance Methods

[](key) click to toggle source

Lookup value in cache

# File lib/sprockets-cache-riak/riak_store.rb, line 17
def [](key)
  object = @bucket.get_or_new sanitize_key(key)
  object.data if object.data
end
[]=(key, value) click to toggle source

Save value to cache

# File lib/sprockets-cache-riak/riak_store.rb, line 23
def []=(key, value)
  object              = @bucket.get_or_new sanitize_key(key)
  object.raw_data     = Marshal.dump(value)
  object.content_type = "application/x-ruby-marshal"
  object.store
  value
end

Private Instance Methods

sanitize_key(key) click to toggle source
# File lib/sprockets-cache-riak/riak_store.rb, line 33
def sanitize_key(key)
  ::Digest::SHA1.hexdigest key
end