Class: Alephant::Cache

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/cache.rb,
lib/alephant/cache/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bucketObject (readonly)

Returns the value of attribute bucket.



8
9
10
# File 'lib/alephant/cache.rb', line 8

def bucket
  @bucket
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/alephant/cache.rb', line 8

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/alephant/cache.rb', line 8

def path
  @path
end

Instance Method Details

#clearObject



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, meta = {})
  bucket.objects["#{path}/#{id}"].write(
    data,
    {
      :metadata => meta
    }
  )

  logger.info("Cache.put: #{path}/#{id}")
end