Class: Rack::Cache::EntityStore::GAEStore

Inherits:
Rack::Cache::EntityStore show all
Defined in:
lib/rack/cache/entity_store.rb

Constant Summary

Constants inherited from Rack::Cache::EntityStore

DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED, NOOP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GAEStore

Returns a new instance of GAEStore.



297
298
299
300
# File 'lib/rack/cache/entity_store.rb', line 297

def initialize(options = {})
  require 'rack/cache/app_engine'
  @cache = Rack::Cache::AppEngine::MemCache.new(options)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



295
296
297
# File 'lib/rack/cache/entity_store.rb', line 295

def cache
  @cache
end

Class Method Details

.resolve(uri) ⇒ Object



330
331
332
# File 'lib/rack/cache/entity_store.rb', line 330

def self.resolve(uri)
  self.new(:namespace => uri.host)
end

Instance Method Details

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


302
303
304
# File 'lib/rack/cache/entity_store.rb', line 302

def exist?(key)
  cache.contains?(key)
end

#open(key) ⇒ Object



310
311
312
313
314
315
316
# File 'lib/rack/cache/entity_store.rb', line 310

def open(key)
  if data = read(key)
    [data]
  else
    nil
  end
end

#purge(key) ⇒ Object



325
326
327
328
# File 'lib/rack/cache/entity_store.rb', line 325

def purge(key)
  cache.delete(key)
  nil
end

#read(key) ⇒ Object



306
307
308
# File 'lib/rack/cache/entity_store.rb', line 306

def read(key)
  cache.get(key)
end

#write(body, ttl = nil) ⇒ Object



318
319
320
321
322
323
# File 'lib/rack/cache/entity_store.rb', line 318

def write(body, ttl=nil)
  buf = StringIO.new
  key, size = slurp(body){|part| buf.write(part) }
  cache.put(key, buf.string, ttl)
  [key, size]
end