alephant-cache 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/cache.rb +10 -6
- data/lib/alephant/cache/version.rb +1 -1
- data/spec/cache_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bffd87081f54072fa6fc2d529398aac88e09661
|
4
|
+
data.tar.gz: bff957d2d404bfb09aca76c16354a5da4b7fbfc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1d433f7652ff3561a4b29b5631d72335496bfb24cf78493d2e20d531c2206fbda63a2aa2d03e29c196dd8561d5d9e29b980fb534b2a08b059e763c757df07d0
|
7
|
+
data.tar.gz: 031990a6cffb28cb84bb3cfa84212b78f9bbe4c86e429ad622166649a8f13c767e32266dab919a1519073ae4414e8230eda6a9f81b5f9af023252130e5bbabfe
|
data/lib/alephant/cache.rb
CHANGED
@@ -11,19 +11,23 @@ module Alephant
|
|
11
11
|
@id = id
|
12
12
|
@path = path
|
13
13
|
|
14
|
-
|
15
|
-
@bucket = s3.buckets[id]
|
14
|
+
@bucket = AWS::S3.new.buckets[id]
|
16
15
|
logger.info("Cache.initialize: end with id #{id} and path #{path}")
|
17
16
|
end
|
18
17
|
|
18
|
+
def clear
|
19
|
+
bucket.objects.with_prefix(path).delete_all
|
20
|
+
logger.info("Cache.clear: #{path}")
|
21
|
+
end
|
22
|
+
|
19
23
|
def put(id, data)
|
20
|
-
|
21
|
-
logger.info("Cache.put: #{
|
24
|
+
bucket.objects["#{path}/#{id}"].write(data)
|
25
|
+
logger.info("Cache.put: #{path}/#{id}")
|
22
26
|
end
|
23
27
|
|
24
28
|
def get(id)
|
25
|
-
logger.info("Cache.get: #{
|
26
|
-
|
29
|
+
logger.info("Cache.get: #{path}/#{id}")
|
30
|
+
bucket.objects["#{path}/#{id}"].read
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
data/spec/cache_spec.rb
CHANGED
@@ -22,6 +22,29 @@ describe Alephant::Cache do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "clear" do
|
26
|
+
let(:num_object_in_path) { 100 }
|
27
|
+
it "deletes all objects for a path" do
|
28
|
+
filtered_object_collection = double()
|
29
|
+
filtered_object_collection
|
30
|
+
.should_receive(:delete_all)
|
31
|
+
|
32
|
+
s3_object_collection = double()
|
33
|
+
s3_object_collection
|
34
|
+
.should_receive(:with_prefix)
|
35
|
+
.with(path)
|
36
|
+
.and_return(filtered_object_collection)
|
37
|
+
|
38
|
+
s3_bucket = double()
|
39
|
+
s3_bucket.should_receive(:objects).and_return(s3_object_collection)
|
40
|
+
|
41
|
+
AWS::S3.any_instance.stub(:buckets).and_return({ id => s3_bucket })
|
42
|
+
|
43
|
+
instance = subject.new(id, path)
|
44
|
+
instance.clear
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
25
48
|
describe "put(id, data)" do
|
26
49
|
it "sets bucket path/id content data" do
|
27
50
|
s3_object_collection = double()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|