Sha256: c06d836111473d8b30c89745831c05de63ed9939366bf1577b0200040b1ca75d

Contents?: true

Size: 792 Bytes

Versions: 9

Compression:

Stored size: 792 Bytes

Contents

module CabbageDoc
  module Worker
    EXPIRES_IN = 30.freeze # 30 seconds

    class << self
      def get(id)
        cache_id = [CabbageDoc::MARKER, id].join('_')
        response = CabbageDoc::Configuration.instance.cache.read(cache_id)

        if response
          CabbageDoc::Configuration.instance.cache.delete(cache_id)
          Response.parse(response)
        end
      end
    end

    def perform(serialized_request)
      request = Request.parse(serialized_request)
      response = request.perform
      write(request.id, response) if response
    end

    private

    def write(id, response)
      CabbageDoc::Configuration.instance.cache.write(
        [CabbageDoc::MARKER, id].join('_'), 
        response.to_yaml,
        expires_in: EXPIRES_IN
      )
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cabbage_doc-0.1.4 lib/cabbage_doc/worker.rb
cabbage_doc-0.1.3 lib/cabbage_doc/worker.rb
cabbage_doc-0.1.2 lib/cabbage_doc/worker.rb
cabbage_doc-0.1.1 lib/cabbage_doc/worker.rb
cabbage_doc-0.1.0 lib/cabbage_doc/worker.rb
cabbage_doc-0.0.9 lib/cabbage_doc/worker.rb
cabbage_doc-0.0.8 lib/cabbage_doc/worker.rb
cabbage_doc-0.0.7 lib/cabbage_doc/worker.rb
cabbage_doc-0.0.6 lib/cabbage_doc/worker.rb