sprockets-cache-riak 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +7 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/lib/sprockets-cache-riak.rb +2 -0
- data/lib/sprockets-cache-riak/riak_store.rb +39 -0
- data/lib/sprockets-cache-riak/version.rb +7 -0
- data/sprockets-cache-riak.gemspec +18 -0
- metadata +60 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2012 Christoph Grabo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Sprockets Riak Cache
|
2
|
+
|
3
|
+
A cache store for Sprockets which utilities Riak.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "sprockets"
|
12
|
+
gem "sprockets-cache-riak"
|
13
|
+
# ...
|
14
|
+
```
|
15
|
+
|
16
|
+
config.ru:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require "sprockets-cache-riak"
|
20
|
+
env = Sprockets::Environment.new
|
21
|
+
env.cache = Sprockets::Cache::RiakStore.new(riak, "sprockets")
|
22
|
+
# ...
|
23
|
+
```
|
24
|
+
|
25
|
+
Where the first argument is a Riak::Client connection (riak-ruby-client by Basho), and the other (which is optional) is a bucket name.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "digest/md5"
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module Cache
|
5
|
+
# A simple Riak cache store.
|
6
|
+
#
|
7
|
+
# environment.cache = Sprockets::Cache::RiakStore.new($riak)
|
8
|
+
#
|
9
|
+
class RiakStore
|
10
|
+
|
11
|
+
def initialize(riak_client, bucket = "sprockets")
|
12
|
+
@riak = riak_client
|
13
|
+
@bucket = @riak.bucket(bucket)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Lookup value in cache
|
17
|
+
def [](key)
|
18
|
+
object = @bucket.get_or_new sanitize_key(key)
|
19
|
+
object.data if object.data
|
20
|
+
end
|
21
|
+
|
22
|
+
# Save value to cache
|
23
|
+
def []=(key, value)
|
24
|
+
object = @bucket.get_or_new sanitize_key(key)
|
25
|
+
object.raw_data = Marshal.dump(value)
|
26
|
+
object.content_type = "application/x-ruby-marshal"
|
27
|
+
object.store
|
28
|
+
value
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def sanitize_key(key)
|
34
|
+
::Digest::SHA1.hexdigest key
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "sprockets-cache-riak/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sprockets-cache-riak"
|
7
|
+
s.version = Sprockets::Cache::Riak::VERSION
|
8
|
+
s.authors = ["Christoph Grabo"]
|
9
|
+
s.email = ["chris@dinarrr.com"]
|
10
|
+
s.homepage = "https://github.com/CarrotCornCat/sprockets-cache-riak"
|
11
|
+
s.summary = %q{A Riak cache store for Sprockets}
|
12
|
+
s.description = %q{A Riak cache store for Sprockets, built on the model of sprockets-cache-redis }
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-cache-riak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christoph Grabo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'A Riak cache store for Sprockets, built on the model of sprockets-cache-redis '
|
15
|
+
email:
|
16
|
+
- chris@dinarrr.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/sprockets-cache-riak.rb
|
27
|
+
- lib/sprockets-cache-riak/riak_store.rb
|
28
|
+
- lib/sprockets-cache-riak/version.rb
|
29
|
+
- sprockets-cache-riak.gemspec
|
30
|
+
homepage: https://github.com/CarrotCornCat/sprockets-cache-riak
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
hash: 3104730376852856882
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
hash: 3104730376852856882
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.23
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: A Riak cache store for Sprockets
|
60
|
+
test_files: []
|