0.0
No commit activity in last 3 years
No release in over 3 years
Memcached plugin for Kuby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

kuby-memcached

Memcached plugin for Kuby.

Intro

The memcached plugin provides the ability to stand up arbitrary memcached instances. Behind the scenes it uses the excellent kubedb Kubernetes operator.

Configuration

Add the kuby-memcached gem to your Gemfile, then add a memcached instance like this:

require 'kuby/memcached'

Kuby.define(:production) do
  kubernetes do

    add_plugin(:memcached) do
      instance(:my_rails_cache)
    end

  end
end

The kuby-memcached plugin allows a number of additional configuration options too:

Kuby.define(:production) do
  kubernetes do

    add_plugin(:memcached) do
      instance(:my_rails_cache) do
        # set the version of memcached you want to use
        version '1.5.4-v1'  # this is the default version

        # set the port memcached listen on and that you'll
        # use to connect to the instance
        port 11211  # this is the default port
      end
    end

  end
end

Get a list of the memcached versions your cluster supports by running:

bundle exec kuby -e production kubectl -- get memcachedversions

Usage

Memcached instances defined in your Kuby config respond to #hostname, #port, and #url methods to help point at them in your Rails configuration. The #url method returns a complete URL to the memcached instance, including the host and port.

Rails Cache

In your Rails config (eg. config/environments/production.rb), point your cache store at your memcached instance like so:

Kuby.load!

url = Kuby.environment.kubernetes
  .plugin(:memcached)
  .instance(:my_rails_cache)
  .url

config.cache_store = :mem_cache_store, url

Dalli

You can also use a memcached client like the Dalli gem directly:

require 'dalli'

url = Kuby.environment.kubernetes
  .plugin(:memcached)
  .instance(:my_rails_cache)
  .url

dc = Dalli::Client.new(url)
dc.set('abc', 123)
value = dc.get('abc')

License

Licensed under the MIT license. See LICENSE for details.

Authors