eternity 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d899599867306841878c64702cb5786909538d3
4
- data.tar.gz: 70a14178c9956a8e3a44bb5cc90ac977f063486c
3
+ metadata.gz: 3b1be717d81a945f05cc68350c5291916a40e37a
4
+ data.tar.gz: 3a4091179e5a901e528acee59c63463c4459437b
5
5
  SHA512:
6
- metadata.gz: b03d8b518b7b32ae744ced5e17ddbd010c4f3495cdfd2b90f702bff7d67e26387a01d532d77e9c84381d08eb0ebe575cc1206f884fb0093875de321979cfd57d
7
- data.tar.gz: 7ae3ebdff6141df8985529030e6bb5a1aec3b1de2e17fd25f1b4fe4364d06166cfbc416dce4ffa119e624aaa7bb2131db250b51ee78c38dd2a51545496c679b7
6
+ metadata.gz: 421fe67444cd8a285666bb6ec41083e9679bc2f0338af5fbc8f7befebf5ae3cf60c8602d474185f7536d4f34021ba6d0d9b9782a1c868041c5d20eeab14dcf55
7
+ data.tar.gz: c5226548c8da91a8dfc3467cfaf25b449dd84af4e0265ffa86cf199fae20303166a2c3fdd182b0657e92cd7f4eeffdf49c9eb5e46e6534428f5ff5dd5eefc86a
data/lib/eternity.rb CHANGED
@@ -21,6 +21,7 @@ module Eternity
21
21
  attr_config :connection, Restruct::Connection.new
22
22
  attr_config :keyspace, Restruct::Id.new(:eternity)
23
23
  attr_config :blob_cache_expiration, 24 * 60 * 60 # 1 day in seconds
24
+ attr_config :blob_cache_max_size, 10 * 1024 * 1024 # 10 MB
24
25
  attr_config :blob_path, File.join(Dir.home, '.eternity')
25
26
  attr_config :logger, Logger.new(STDOUT)
26
27
 
data/lib/eternity/blob.rb CHANGED
@@ -58,7 +58,7 @@ module Eternity
58
58
  end
59
59
  end
60
60
 
61
- def count
61
+ def cache_size
62
62
  Eternity.connection.call('KEYS', Eternity.keyspace[:blob]['*']).count
63
63
  end
64
64
 
@@ -88,8 +88,10 @@ module Eternity
88
88
  private
89
89
 
90
90
  def write_redis(type, sha1, serialization)
91
- Eternity.connection.call 'SET', Eternity.keyspace[:blob][type][sha1], serialization,
92
- 'EX', Eternity.blob_cache_expiration
91
+ if serialization.size <= Eternity.blob_cache_max_size
92
+ Eternity.connection.call 'SET', Eternity.keyspace[:blob][type][sha1], serialization,
93
+ 'EX', Eternity.blob_cache_expiration
94
+ end
93
95
  end
94
96
 
95
97
  def read_redis(type, sha1)
@@ -1,3 +1,3 @@
1
1
  module Eternity
2
- VERSION = '0.1.3'
2
+ VERSION = '1.0.0'
3
3
  end
data/spec/blob_spec.rb CHANGED
@@ -27,6 +27,14 @@ describe Blob do
27
27
  raise "File not found: #{filename}"
28
28
  end
29
29
 
30
+ def with_cache_size(limit)
31
+ blob_cache_max_size = Eternity.blob_cache_max_size
32
+ Eternity.blob_cache_max_size = limit
33
+ yield
34
+ ensure
35
+ Eternity.blob_cache_max_size = blob_cache_max_size
36
+ end
37
+
30
38
  it 'Write in redis and file system' do
31
39
  sha1 = Blob.write :xyz, data
32
40
 
@@ -36,6 +44,18 @@ describe Blob do
36
44
  [redis_data, decode(file_data)].each { |d| MessagePack.unpack(d).must_equal data }
37
45
  end
38
46
 
47
+ it 'Write only in file system' do
48
+ with_cache_size 0 do
49
+ sha1 = Blob.write :xyz, data
50
+
51
+ redis_data = connection.call 'GET', key
52
+ redis_data.must_be_nil
53
+
54
+ file_data = wait_and_read_file filename
55
+ MessagePack.unpack(decode(file_data)).must_equal data
56
+ end
57
+ end
58
+
39
59
  it 'Read from redis' do
40
60
  connection.call 'SET', key, serialization
41
61
 
@@ -56,12 +76,12 @@ describe Blob do
56
76
  error.message.must_equal 'Blob not found: xyz -> invalid_sha1'
57
77
  end
58
78
 
59
- it 'Count' do
60
- Blob.count.must_equal 0
79
+ it 'Cache size' do
80
+ Blob.cache_size.must_equal 0
61
81
 
62
82
  3.times { |i| Blob.write :xyz, value: i }
63
83
 
64
- Blob.count.must_equal 3
84
+ Blob.cache_size.must_equal 3
65
85
  end
66
86
 
67
87
  it 'Clear cache' do
@@ -69,7 +89,7 @@ describe Blob do
69
89
 
70
90
  Blob.clear_cache
71
91
 
72
- Blob.count.must_equal 0
92
+ Blob.cache_size.must_equal 0
73
93
  end
74
94
 
75
95
  it 'Normalize serialization' do
@@ -18,6 +18,7 @@ Eternity.configure do |config|
18
18
  config.keyspace = Restruct::Id.new :eternity_test
19
19
  config.blob_path = File.expand_path('../../tmp', __FILE__)
20
20
  config.blob_cache_expiration = 30
21
+ config.blob_cache_max_size = 50
21
22
  config.logger.level = Logger::ERROR
22
23
  end
23
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eternity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restruct