Class: Alephant::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/alephant/models/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, path) ⇒ Cache

Returns a new instance of Cache.



7
8
9
10
11
12
13
14
15
# File 'lib/alephant/models/cache.rb', line 7

def initialize(id, path)
  @logger = ::Alephant.logger
  @id = id
  @path = path

  s3 = AWS::S3.new
  @bucket = s3.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.



5
6
7
# File 'lib/alephant/models/cache.rb', line 5

def bucket
  @bucket
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/alephant/models/cache.rb', line 5

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/alephant/models/cache.rb', line 5

def path
  @path
end

Instance Method Details

#get(id) ⇒ Object



22
23
24
25
# File 'lib/alephant/models/cache.rb', line 22

def get(id)
  @logger.info("Cache.get: #{@path}/#{id}")
  @bucket.objects["#{@path}/#{id}"].read
end

#put(id, data) ⇒ Object



17
18
19
20
# File 'lib/alephant/models/cache.rb', line 17

def put(id, data)
  @bucket.objects["#{@path}/#{id}"].write(data)
  @logger.info("Cache.put: #{@path}/#{id}")
end