Class: Rack::Cache::AppEngine::MemCache

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/cache/app_engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MemCache

Returns a new instance of MemCache.



16
17
18
19
# File 'lib/rack/cache/app_engine.rb', line 16

def initialize(options = {})
  @cache = MC::Service
  @cache.namespace = options[:namespace] if options[:namespace]
end

Instance Method Details

#contains?(key) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rack/cache/app_engine.rb', line 21

def contains?(key)
  MC::Service.contains(key)
end

#delete(key) ⇒ Object



44
45
46
# File 'lib/rack/cache/app_engine.rb', line 44

def delete(key)
  MC::Service.delete(key)
end

#get(key) ⇒ Object



25
26
27
28
# File 'lib/rack/cache/app_engine.rb', line 25

def get(key)
  value = MC::Service.get(key)
  Marshal.load(Base64.decode64(value)) if value
end

#namespaceObject



36
37
38
# File 'lib/rack/cache/app_engine.rb', line 36

def namespace
  MC::Service.getNamespace
end

#namespace=(value) ⇒ Object



40
41
42
# File 'lib/rack/cache/app_engine.rb', line 40

def namespace=(value)
  MC::Service.setNamespace(value.to_s)
end

#put(key, value, ttl = nil) ⇒ Object



30
31
32
33
34
# File 'lib/rack/cache/app_engine.rb', line 30

def put(key, value, ttl = nil)
  expiration = ttl ? MC::Expiration.byDeltaSeconds(ttl) : nil
  value = Base64.encode64(Marshal.dump(value)).gsub(/\n/, '')
  MC::Service.put(key, value, expiration)
end