Files

Padrino::Cache::Store::Memcache

Memcache Cache Store

Public Class Methods

new(client, options={}) click to toggle source

Initialize Memcache store with client connection.

@param client

instance of Memcache library

@example

Padrino.cache = Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211'))
Padrino.cache = Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
# or from your app
set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211'))
set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))

@api public

# File lib/padrino-cache/store/memcache.rb, line 22
def initialize(client, options={})
  @backend = client
  super(options)
  @never = 0  # never TTL in Memcache is 0
end

Public Instance Methods

delete(key) click to toggle source

Delete the value for a given key

@param [String] key

cache key

@example

# with: MyApp.cache.set('records', records)
MyApp.cache.delete('records')

@api public

# File lib/padrino-cache/store/memcache.rb, line 74
def delete(key)
  @backend.delete(key)
end
flush() click to toggle source

Reinitialize your cache

@example

# with: MyApp.cache.set('records', records)
MyApp.cache.flush
MyApp.cache.get('records') # => nil

@api public

# File lib/padrino-cache/store/memcache.rb, line 87
def flush
  @backend.respond_to?(:flush_all) ? @backend.flush_all : @backend.flush
end
get(key) click to toggle source

Return the a value for the given key

@param [String] key

cache key to retrieve value

@example

# with MyApp.cache.set('records', records)
MyApp.cache.get('records')

@api public

# File lib/padrino-cache/store/memcache.rb, line 39
def get(key)
  @backend.get(key)
rescue Memcached::NotFound
  nil
end
set(key, value, opts = nil) click to toggle source

Set the value for a given key and optionally with an expire time Default expiry time is 86400.

@param [String] key

cache key

@param value

value of cache key

@example

MyApp.cache.set('records', records)
MyApp.cache.set('records', records, :expires_in => 30) # => 30 seconds

@api public

# File lib/padrino-cache/store/memcache.rb, line 59
def set(key, value, opts = nil)
  @backend.set(key, value, get_expiry(opts))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.