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.



291
292
293
294
# File 'lib/rack/cache/entity_store.rb', line 291

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.



289
290
291
# File 'lib/rack/cache/entity_store.rb', line 289

def cache
  @cache
end

Class Method Details

.resolve(uri) ⇒ Object



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

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

Instance Method Details

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#open(key) ⇒ Object



304
305
306
307
308
309
310
# File 'lib/rack/cache/entity_store.rb', line 304

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

#purge(key) ⇒ Object



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

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

#read(key) ⇒ Object



300
301
302
# File 'lib/rack/cache/entity_store.rb', line 300

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

#write(body, ttl = nil) ⇒ Object



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

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