Skip to content

Instantly share code, notes, and snippets.

@adamhunter
Created June 20, 2011 16:23
Show Gist options
  • Save adamhunter/1035927 to your computer and use it in GitHub Desktop.
Save adamhunter/1035927 to your computer and use it in GitHub Desktop.

Revisions

  1. adamhunter revised this gist Jun 20, 2011. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions riak_cache.rb
    Original file line number Diff line number Diff line change
    @@ -9,14 +9,14 @@ def initialize

    def read(key)
    @object = @bucket.get(key)
    Marshal.load(@object.data)
    @object.data
    end

    def write(key, value)
    @object = Riak::RObject.new(@bucket, key)
    @object.content_type = 'text/plain'
    @object.data = Marshal.dump(value)
    @object = @bucket.get_or_new(key)
    @object.content_type = 'application/x-ruby-marshal'
    @object.data = value
    @object.store
    end

    end
    end
  2. adamhunter created this gist Jun 20, 2011.
    22 changes: 22 additions & 0 deletions riak_cache.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    require 'riak'

    class RiakCache

    def initialize
    @client = Riak::Client.new(:pb_port => 8081, :protocol => :pbc)
    @bucket = @client.bucket("riakcache")
    end

    def read(key)
    @object = @bucket.get(key)
    Marshal.load(@object.data)
    end

    def write(key, value)
    @object = Riak::RObject.new(@bucket, key)
    @object.content_type = 'text/plain'
    @object.data = Marshal.dump(value)
    @object.store
    end

    end