Class: Alephant::Cache
- Inherits:
-
Object
- Object
- Alephant::Cache
- Includes:
- Logger
- Defined in:
- lib/alephant/cache.rb,
lib/alephant/cache/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #clear ⇒ Object
- #get(id) ⇒ Object
-
#initialize(id, path) ⇒ Cache
constructor
A new instance of Cache.
- #put(id, data, meta = {}) ⇒ Object
Constructor Details
#initialize(id, path) ⇒ Cache
Returns a new instance of Cache.
10 11 12 13 14 15 16 |
# File 'lib/alephant/cache.rb', line 10 def initialize(id, path) @id = id @path = path @bucket = AWS::S3.new.buckets[id] logger.info("Cache.initialize: end with id #{id} and path #{path}") end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
8 9 10 |
# File 'lib/alephant/cache.rb', line 8 def bucket @bucket end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/alephant/cache.rb', line 8 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/alephant/cache.rb', line 8 def path @path end |
Instance Method Details
#clear ⇒ Object
18 19 20 21 |
# File 'lib/alephant/cache.rb', line 18 def clear bucket.objects.with_prefix(path).delete_all logger.info("Cache.clear: #{path}") end |
#get(id) ⇒ Object
34 35 36 37 |
# File 'lib/alephant/cache.rb', line 34 def get(id) logger.info("Cache.get: #{path}/#{id}") bucket.objects["#{path}/#{id}"].read end |
#put(id, data, meta = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/alephant/cache.rb', line 23 def put(id, data, = {}) bucket.objects["#{path}/#{id}"].write( data, { :metadata => } ) logger.info("Cache.put: #{path}/#{id}") end |