Class: Sprockets::Cache::RiakStore

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets-cache-riak/riak_store.rb

Overview

A simple Riak cache store.

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

Instance Method Summary collapse

Constructor Details

#initialize(riak_client, bucket = "sprockets") ⇒ RiakStore

Returns a new instance of RiakStore.



11
12
13
14
# File 'lib/sprockets-cache-riak/riak_store.rb', line 11

def initialize(riak_client, bucket = "sprockets")
  @riak   = riak_client
  @bucket = @riak.bucket(bucket)
end

Instance Method Details

#[](key) ⇒ Object

Lookup value in cache



17
18
19
20
# 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) ⇒ Object

Save value to cache



23
24
25
26
27
28
29
# 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