The 5.7 branch of Magnolia reached End-of-Life on December 31, 2023, as specified in our End-of-life policy. This means the 5.7 branch is no longer maintained or supported. Please upgrade to the latest Magnolia release. By upgrading, you will get the latest release of Magnolia featuring significant improvements to the author and developer experience. For a successful upgrade, please consult our Magnolia 6.2 documentation. If you need help, please contact info@magnolia-cms.com.

Memcached is a high-performance, distributed memory object caching system. Memcached implementation for Magnolia CMS brings you the advantages of a distributed cache:

  • Sharing of cache items between multiple instances of Magnolia.
  • Cached items persist restart of Magnolia instance.
  • Memcached servers may run on any server in the network and so do not consume your server memory.

Installing

Maven is the easiest way to install the module. Add the following to your bundle. The parent POM of your webapp project should set the latest version of the module automatically. Should you need to use a specific module version, you can define it using the <version/> in the dependency.

<dependency>
  <groupId>info.magnolia.cache</groupId>
  <artifactId>magnolia-cache-memcached</artifactId>
</dependency>

If you extend your web app from a magnolia-empty-webapp or any other web app extended from it (such as magnolia-bundled-webapp) you also need to exclude the default ehcache implementation:

    <dependency>
      <groupId>info.magnolia</groupId>
      <artifactId>magnolia-empty-webapp</artifactId>
      <type>pom</type>
      <exclusions>
        <exclusion>
          <groupId>info.magnolia.cache</groupId>
      	  <artifactId>magnolia-cache-ehcache</artifactId>
        </exclusion>  
	  </exclusions>      
    </dependency>

Usage

If you've never used memcached, look at how to install memcached server. You need at least one memcache server per cache. That means for every cache configuration under /modules/cache/config/contentCaching you need one entry under /modules/cache/config/cacheFactory/caches. This is at least (by default) defaultPageCache and uuid-key-mapping.

Magnolia Memcached implementation uses Spymemcached client which has its own configuration options that can be set in /modules/cache/config/cacheFactory/CACHE_NAME.

Node nameValue

 
cacheFactory


    

 
class

info.magnolia.cache.memcached.spy.MemcachedFactory

    

 
caches


        

 
defaultPageCache


            

 
class

info.magnolia.cache.memcached.spy.MemcachedConnectionFactoryBuilder

            

 
readBufSizeN2B

10000

            

 
useNagleAlgorithmN2B

true

            

 
protocolN2B

BINARY

            

 
timeoutExceptionThresholdN2B

998

            

 
opQueueMaxBlockTimeN2B

-1

            

 
shouldOptimizeN2B

false

            

 
opTimeoutN2B

-1

            

 
daemonN2B

false

            

 
maxReconnectDelayN2B

30

            

 
servers


                

 
0

localhost:11211

        

 
uuid-key-mapping


            

 
extends

../defaultPageCache

            

 
servers


                

 
0

localhost:11212

Properties:


ParameterDefault valueDescription / Available values
protocolN2BBINARY BINARY or TEXT protocol.
readBufSizeN2B10000Size of the read buffer.
shouldOptimizeN2BfalseThere are several elements of the design that each allow high throughput.
useNagleAlgorithmN2BtrueImproves the efficiency of TCP/IP networks by reducing the number of packets that need to be sent over the network.
maxReconnectDelayN2B30

Set the maximum reconnect delay.

opQueueMaxBlockTimeN2B1000

Set the maximum amount of time (in milliseconds) a client is willing to wait for space to become available in an output queue.

timeoutExceptionThresholdN2B998

Set the maximum timeout exception threshold.

opTimeoutN2B-1

Set the default operation timeout in milliseconds.

failureModeN2BRedistribute
  • Redistribute (Move on to functional nodes when nodes fail)
  • Retry (Continue to retry a failing node until it comes back up)
  • Cancel (Automatically cancel all operations heading towards a downed node)
transcoderN2Bnet.spy.memcached.transcoders.SerializingTranscoder

Needs to be set as content node with class property:

  • net.spy.memcached.transcoders.SerializingTranscoder
  • net.spy.memcached.transcoders.WhalinTranscoder
  • net.spy.memcached.transcoders.WhalinV1Transcoder
  • net.spy.memcached.transcoders.IntegerTranscoder
  • net.spy.memcached.transcoders.LongTranscoder
locatorN2BARRAY_MOD
  • ARRAY_MOD (the classic node location algorithm)
  • VBUCKET (VBucket support)
  • CONSISTENT (Consistent hash algorithm)
servers-Memcache server/s to use for this cache in format <domain or ip>:<port number>

Performance

One of the advantages of the memcached implementation is the sharing of cache entries between multiple instances of Magnolia.  If the cache item is processed by one of the public instances, it is sent to memcached server/s and other Magnolia instances do not need to render the content again; instead they may use the item cached in the registered memcached servers.

For the following tests, we requested content from two Magnolia instances at the same time.  You can see the results on the first graph.  As you can see the throughput is 2x bigger since the instances share the cache items.  This of course applies only for the first requests for a content object, but that's the time after flushing of cache when the load on the server is highest.

The second graph shows performance when the items are precached.  Memcached is a little slower than Ehcache in this case.

Bar chart for First requests Comparative resultsBar chart for Precached Comparative results

Memcached Client License

Please note that the Spymemcached client uses its own licence:

Spymemcached license

/**
* Copyright (c) 2006-2009 Dustin Sallings
* Copyright (c) 2009-2011 Couchbase, Inc.

  *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
* IN THE SOFTWARE.
*/