Sha256: 8d8169588a017b9855f37e99feb3c47dfdc798036fb35ba933e20364f469b017

Contents?: true

Size: 793 Bytes

Versions: 1

Compression:

Stored size: 793 Bytes

Contents

require 'alephant/cache/version'
require 'alephant/logger'
require 'aws-sdk'

module Alephant
  class Cache
    include Logger
    attr_reader :id, :bucket, :path

    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

    def clear
      bucket.objects.with_prefix(path).delete_all
      logger.info("Cache.clear: #{path}")
    end

    def put(id, data, meta = {})
      bucket.objects["#{path}/#{id}"].write(
        data,
        {
          :metadata => meta
        }
      )

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-cache-0.0.4 lib/alephant/cache.rb