big_cache 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +48 -0
- data/Rakefile +12 -0
- data/bin/big_cache +3 -0
- data/lib/big_cache.rb +74 -0
- data/test/test_big_cache.rb +8 -0
- metadata +74 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= big_cache
|
2
|
+
|
3
|
+
http://www.crankapps.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Infinite size, persistent cache using Amazon S3 for storage.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2009 FIX
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/big_cache.rb'
|
6
|
+
|
7
|
+
Hoe.new('big_cache', ActiveSupport::Cache::BigCache::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'spacegems' # if different than lowercase project name
|
9
|
+
p.developer('Travis Reeder', 'travis@crankapps.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
# vim: syntax=Ruby
|
data/bin/big_cache
ADDED
data/lib/big_cache.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'right_aws'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module Cache
|
6
|
+
|
7
|
+
class BigCache < Store
|
8
|
+
|
9
|
+
VERSION = '1.0.0'
|
10
|
+
def initialize(bucket_name, access_key, secret_key)
|
11
|
+
puts 'Creating new BigCache'
|
12
|
+
@s3 = RightAws::S3.new(access_key, secret_key)
|
13
|
+
@bucket = @s3.bucket(bucket_name, true)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(key)
|
18
|
+
# if the API URL exists as a key in cache, we just return it
|
19
|
+
# we also make sure the data is fresh
|
20
|
+
key = @bucket.key(key)
|
21
|
+
if !key.exists?
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
cache_entry = key.data
|
25
|
+
puts 'cache_entry=' + cache_entry
|
26
|
+
index = cache_entry.index('::')
|
27
|
+
puts 'index=' + index.to_s
|
28
|
+
expires = cache_entry[0..index].to_i
|
29
|
+
puts 'expires in get=' + expires.to_s
|
30
|
+
expires2 = (expires - Time.now.to_i)
|
31
|
+
if expires2 > 0
|
32
|
+
# puts 'returning from cache ' + @cache[key][1].inspect
|
33
|
+
return Marshal.load(cache_entry[(index+2)...cache_entry.length])
|
34
|
+
else
|
35
|
+
# puts 'expired=' + key + ' at ' + expires.to_s + ' and now=' + Time.now.to_s
|
36
|
+
@bucket.key(key).delete # do async
|
37
|
+
end
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def put(key, val, seconds_to_store)
|
42
|
+
seconds_to_store = seconds_to_store || 9999999
|
43
|
+
puts 'seconds=' + seconds_to_store.to_s
|
44
|
+
data = Marshal.dump(val)
|
45
|
+
@bucket.put(key, (Time.now+seconds_to_store).to_i.to_s + "::" + data)
|
46
|
+
end
|
47
|
+
|
48
|
+
def read(name, options = nil)
|
49
|
+
# puts 'read from localcache'
|
50
|
+
super
|
51
|
+
ret = get(name)
|
52
|
+
# puts 'ret.frozen=' + ret.frozen?.to_s
|
53
|
+
return ret
|
54
|
+
end
|
55
|
+
|
56
|
+
def write(name, value, options = nil)
|
57
|
+
super
|
58
|
+
put(name, value, options.nil? ? nil : options[:expires_in])
|
59
|
+
# puts 'write.frozen=' + value.frozen?.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete(name, options = nil)
|
63
|
+
super
|
64
|
+
@bucket.key(name).delete
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete_matched(matcher, options = nil)
|
68
|
+
super
|
69
|
+
raise "delete_matched not supported by BigCache"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: big_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Reeder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.12.2
|
24
|
+
version:
|
25
|
+
description: Infinite size, persistent cache using Amazon S3 for storage.
|
26
|
+
email:
|
27
|
+
- travis@crankapps.com
|
28
|
+
executables:
|
29
|
+
- big_cache
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- bin/big_cache
|
42
|
+
- lib/big_cache.rb
|
43
|
+
- test/test_big_cache.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://www.crankapps.com
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --main
|
51
|
+
- README.txt
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: spacegems
|
69
|
+
rubygems_version: 1.3.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Infinite size, persistent cache using Amazon S3 for storage.
|
73
|
+
test_files:
|
74
|
+
- test/test_big_cache.rb
|