Class: Hoodoo::TransientStore::Memcached

Inherits:
Base
  • Object
show all
Defined in:
lib/hoodoo/transient_store/transient_store/memcached.rb

Overview

Hoodoo::TransientStore plugin for Memcached. The Dalli gem is used for server communication.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage_host_uri:, namespace:) ⇒ Memcached

See Hoodoo::TransientStore::Base::new for details.

Do not instantiate this class directly. Use Hoodoo::TransientStore::new.

The Dalli gem is used to talk to Memcached and accepts connection UIRs of simple, terse forms such as 'localhost:11211'. Connections are configured with JSON serialisation, compression off and a forced namespace of nz_co_loyalty_hoodoo_transient_store_ to avoid collision of data stored with this object and other data that may be in the Memcached instance identified by storage_host_uri.



45
46
47
48
# File 'lib/hoodoo/transient_store/transient_store/memcached.rb', line 45

def initialize( storage_host_uri:, namespace: )
  super # Pass all arguments through -> *not* 'super()'
  @client = connect_to_memcached( storage_host_uri, namespace )
end

Instance Attribute Details

#clientObject

Overrideable access to this object’s Dalli::Client instance. It is inadvisable to couple calling code directly into this interface as it is a Hoodoo::TransientStore::Memcached specialisation, but if deemed absolutely necessary the Dalli client can be override with a customised version.



30
31
32
# File 'lib/hoodoo/transient_store/transient_store/memcached.rb', line 30

def client
  @client
end

Instance Method Details

#closeObject

See Hoodoo::TransientStore::Base#close for details.



72
73
74
# File 'lib/hoodoo/transient_store/transient_store/memcached.rb', line 72

def close
  @client.close()
end

#delete(key:) ⇒ Object

See Hoodoo::TransientStore::Base#delete for details.



65
66
67
68
# File 'lib/hoodoo/transient_store/transient_store/memcached.rb', line 65

def delete( key: )
  @client.delete( key )
  true
end

#get(key:) ⇒ Object

See Hoodoo::TransientStore::Base#get for details.



59
60
61
# File 'lib/hoodoo/transient_store/transient_store/memcached.rb', line 59

def get( key: )
  @client.get( key )
end

#set(key:, payload:, maximum_lifespan:) ⇒ Object

See Hoodoo::TransientStore::Base#set for details.



52
53
54
55
# File 'lib/hoodoo/transient_store/transient_store/memcached.rb', line 52

def set( key:, payload:, maximum_lifespan: )
  @client.set( key, payload, maximum_lifespan )
  true
end