s3cache 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/s3cache.rb +12 -10
  3. metadata +2 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2864f8ce4c8dcfeff913d831aa3f9b1b9e3adbb8
4
- data.tar.gz: 448bb973a9b930f59cc79e67f9d935e49fe1e6a6
3
+ metadata.gz: 240e7d859e3d0f43d52b84ca4baa761176c5c1c8
4
+ data.tar.gz: 57b3aab0d8752994780cc2f124e4e56cf3a4ac6a
5
5
  SHA512:
6
- metadata.gz: 29dff18cf4bdf462a3b2e7763b37d675df6314b5b90b0b9fc7499942c90d0e409ce1a596c0dd83c07231791e49ecfa88f91204f0c349444565b617cf19ec280d
7
- data.tar.gz: 7135a8ec19821db2a4544476f32e6063faf3ca62e9a5bc70edd4405865af81baf1b546539020606e828253b2301d20e9a40f1366907241cd2935b701d534af4b
6
+ metadata.gz: ca3aa5a3c7105ef2ae88c841a1dc6a065fc7600261a069f095b0c046915cb0b9716e4b74e277bb1189a7a2e3b837c175e8100b995584d01b805807c03ef1fd70
7
+ data.tar.gz: ad54c92fd21df4cb149efb62d0907be549bdfc42bd265434cf1ad2c262d3d157fe0b1704734cc2e25da6d1a4ec2c080348970b96c7c0eeb64cfd5f974dc7a12c
data/lib/s3cache.rb CHANGED
@@ -5,24 +5,25 @@ require 'yaml'
5
5
 
6
6
  class S3Cache
7
7
 
8
- VERSION = "0.9.1"
8
+ VERSION = "0.9.2"
9
9
 
10
10
  def initialize(**params)
11
11
 
12
+ @logger = Rails.logger ? Rails.logger : Logger.new(STDOUT)
13
+
12
14
  if not params.to_h[:bucket_name]
13
- puts "requires {:bucket_name => String, (optional) :expires => Integer, (optional) :debug => Boolean }"
15
+ @logger.info{ "requires {:bucket_name => String, (optional) :expires => Integer}" }
14
16
  end
15
17
 
16
18
  @bucket_name = params.to_h[:bucket_name]
17
19
  @expires = params.to_h[:expires] ? params.to_h[:expires] : 32.days
18
- @debug = params.to_h[:debug] ? params.to_h[:debug] : false
19
20
 
20
21
  if ENV['AWS_ACCESS_KEY_ID'].nil? || ENV['AWS_SECRET_ACCESS_KEY'].nil?
21
22
  puts 'Enviroment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be defined. Learn more http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#config-settings-and-precedence'
22
23
  else
23
24
  @s3 = Aws::S3::Client.new
24
25
  if not bucket_exist?
25
- puts "creating bucket #{@bucket_name}" if @debug
26
+ @logger.debug( "creating bucket #{@bucket_name}" )
26
27
  bucket_create
27
28
  end
28
29
  end
@@ -30,7 +31,7 @@ class S3Cache
30
31
 
31
32
  def read(key, **params)
32
33
  key_name = cache_key( key )
33
- puts "read #{key_name}" if @debug
34
+ @logger.debug( "read #{key_name}" )
34
35
  if exist?(key_name)
35
36
  Marshal.load(@s3.get_object({ bucket: @bucket_name, key: key_name }).body.read)
36
37
  else
@@ -40,7 +41,7 @@ class S3Cache
40
41
 
41
42
  def write(key, contents, **params)
42
43
  key_name = cache_key( key )
43
- puts "write #{key_name}" if @debug
44
+ @logger.debug( "write #{key_name}" )
44
45
  @s3.put_object({
45
46
  bucket: @bucket_name,
46
47
  key: key_name,
@@ -53,10 +54,10 @@ class S3Cache
53
54
  key_name = cache_key( key )
54
55
 
55
56
  if(exist?(key_name) )
56
- puts "fetch->read #{key_name}" if @debug
57
+ @logger.debug( "fetch->read #{key_name}" )
57
58
  read (key_name)
58
59
  else
59
- puts "fetch->write #{key_name}" if @debug
60
+ @logger.debug( "fetch->write #{key_name}" )
60
61
  value = yield
61
62
  write(key_name, value)
62
63
  read (key_name)
@@ -70,13 +71,14 @@ class S3Cache
70
71
  rescue
71
72
  response = nil
72
73
  end
73
- puts "exists? #{response} #{key_name}" if @debug
74
+
75
+ @logger.debug( "exists? #{!response.nil?} #{key_name}" )
74
76
  return !response.nil?
75
77
  end
76
78
 
77
79
  def clear
78
80
  cache_keys.each do |key|
79
- puts "deleting key #{key}" if @debug
81
+ @logger.debug( "deleting key #{key}" )
80
82
  @s3.delete_object({:bucket => @bucket_name, :key => key})
81
83
  end
82
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie A Tejeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,4 +94,3 @@ specification_version: 4
94
94
  summary: A simple caching library that serializes objects to the filesystem and is
95
95
  compatible with the Rails.cache API
96
96
  test_files: []
97
- has_rdoc: