sprockets-cache-mongodb 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/Gemfile.lock +14 -0
- data/LICENSE +7 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/lib/sprockets-cache-mongodb.rb +2 -0
- data/lib/sprockets-cache-mongodb/mongodb_store.rb +39 -0
- data/lib/sprockets-cache-mongodb/version.rb +7 -0
- data/sprockets-cache-mongodb.gemspec +18 -0
- metadata +62 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
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 MongoDB Cache
|
2
|
+
|
3
|
+
A cache store for Sprockets which utilities MongoDB.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'sprockets'
|
12
|
+
gem 'sprockets-cache-mongodb'
|
13
|
+
# ...
|
14
|
+
```
|
15
|
+
|
16
|
+
config.ru:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'sprockets-cache-mongodb'
|
20
|
+
env = Sprockets::Environment.new
|
21
|
+
env.cache = Sprockets::Cache::MongoDBStore.new(mongo, 'sprockets')
|
22
|
+
# ...
|
23
|
+
```
|
24
|
+
|
25
|
+
Where the first argument is a Mongo connection (mongo-ruby-driver by 10gen), and the other (which is optional) is a database name.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Sprockets
|
2
|
+
module Cache
|
3
|
+
# A simple MongoDB cache store.
|
4
|
+
#
|
5
|
+
# environment.cache = Sprockets::Cache::MongoDBStore.new($mongo)
|
6
|
+
#
|
7
|
+
class MongoDBStore
|
8
|
+
|
9
|
+
def initialize(mongo_conn, db_name = 'sprockets')
|
10
|
+
@mongo = ::Mongo::Grid.new( mongo_conn.db(db_name) )
|
11
|
+
end
|
12
|
+
|
13
|
+
# Lookup value in cache
|
14
|
+
def [](key)
|
15
|
+
sanitized_key = sanitize_key(key)
|
16
|
+
return unless @mongo.exist?(:filename => sanitized_key)
|
17
|
+
object = @mongo.get sanitized_key
|
18
|
+
data = object.read
|
19
|
+
Marshal.load data if data
|
20
|
+
end
|
21
|
+
|
22
|
+
# Save value to cache
|
23
|
+
def []=(key, value)
|
24
|
+
@mongo.put Marshal.dump(value),
|
25
|
+
:_id => sanitize_key(key),
|
26
|
+
:filename => sanitize_key(key),
|
27
|
+
:content_type => "application/x-ruby-marshal"
|
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-mongodb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sprockets-cache-mongodb"
|
7
|
+
s.version = Sprockets::Cache::MongoDB::VERSION
|
8
|
+
s.authors = ["Christoph Grabo"]
|
9
|
+
s.email = ["chris@dinarrr.com"]
|
10
|
+
s.homepage = "https://github.com/CarrotCornCat/sprockets-cache-mongodb"
|
11
|
+
s.summary = %q{A MongoDB (GridFS) cache store for Sprockets}
|
12
|
+
s.description = %q{A MongoDB (GridFS) 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,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-cache-mongodb
|
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 MongoDB (GridFS) cache store for Sprockets, built on the model of
|
15
|
+
sprockets-cache-redis '
|
16
|
+
email:
|
17
|
+
- chris@dinarrr.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/sprockets-cache-mongodb.rb
|
29
|
+
- lib/sprockets-cache-mongodb/mongodb_store.rb
|
30
|
+
- lib/sprockets-cache-mongodb/version.rb
|
31
|
+
- sprockets-cache-mongodb.gemspec
|
32
|
+
homepage: https://github.com/CarrotCornCat/sprockets-cache-mongodb
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
hash: -2967228152877354406
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
hash: -2967228152877354406
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.23
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: A MongoDB (GridFS) cache store for Sprockets
|
62
|
+
test_files: []
|