Class: AWS::S3::S3Object
- Inherits:
-
Object
- Object
- AWS::S3::S3Object
- Defined in:
- lib/cache/aws/s3/object.rb
Class Method Summary collapse
- .cache_local(value, key, bucket, options = {}) ⇒ Object
- .cached_local?(key, bucket) ⇒ Boolean
-
.file_path!(key, bucket, options = {}) ⇒ Object
:nodoc:.
- .perge_local!(key, bucket) ⇒ Object
- .read_cache(key, bucket, options = {}) ⇒ Object
-
.s3_value ⇒ Object
save old value method.
-
.value(key, bucket = nil, options = {}, &block) ⇒ Object
TODO: ignoring the &block for the moment.
Class Method Details
.cache_local(value, key, bucket, options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/cache/aws/s3/object.rb', line 49 def cache_local(value,key,bucket,={}) fp=file_path!(key,bucket,) FileUtils.mkdir_p File.dirname fp File.open(fp,'w') {|io| io.write value.response} end |
.cached_local?(key, bucket) ⇒ Boolean
70 71 72 73 |
# File 'lib/cache/aws/s3/object.rb', line 70 def cached_local?(key,bucket) #return file exists? at file_path!(bucket,name) File.exists? file_path!(key,bucket) end |
.file_path!(key, bucket, options = {}) ⇒ Object
:nodoc:
55 56 57 58 59 60 61 62 |
# File 'lib/cache/aws/s3/object.rb', line 55 def file_path!(key,bucket, = {}) #:nodoc: # We're using the second argument for options if bucket.is_a?(Hash) .replace(bucket) bucket = nil end File.join(S3FileCache.cache_dir, bucket_name(bucket), key) end |
.perge_local!(key, bucket) ⇒ Object
64 65 66 67 68 |
# File 'lib/cache/aws/s3/object.rb', line 64 def perge_local!(key,bucket) #return delete file at file_path!(bucket,name) file_path= file_path!(key,bucket) File.unlink file_path if File.exists? file_path end |
.read_cache(key, bucket, options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/cache/aws/s3/object.rb', line 44 def read_cache(key,bucket,={}) data = File.open(file_path!(key,bucket, )) {|f| f.read} Value.new OpenStruct.new(:body=>data) end |
.s3_value ⇒ Object
save old value method
22 |
# File 'lib/cache/aws/s3/object.rb', line 22 alias s3_value value |
.value(key, bucket = nil, options = {}, &block) ⇒ Object
TODO: ignoring the &block for the moment
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cache/aws/s3/object.rb', line 25 def value(key, bucket = nil, = {}, &block) return s3_value(key,bucket,,&block) if not S3FileCache.enabled? if cached_local? key, bucket #return cached object read_cache(key,bucket,) else #1. open normal S3 file value = s3_value(key,bucket,) #omitting the block for now #2. save local to file_path! (make parent directories) cache_local(value,key,bucket,) #3. return the value object value end end |