01926 311880

Orchard CMS: Configuring NHibernate Second Level Caching for Azure using On-role caching (Azure Caching Preview)

Gravatar Image by Carl Berisford-Murray

THIS MODULE WILL ONLY WORK WITH ORCHARD 1.6

Firstly download the MemCacheD module.

Right now it can be found at: https://bitbucket.org/Webmoco/azurememcached

Add the module to the azure solution. Don’t forget to add the project and a reference to the project in Orchard.Azure.Web.

You should also remove the SysCache module. The SysCache module can’t co-exist with the AzureMemcached module.

At this point we need to add the actual cache. You have a choice too; either create a new role (which means you need to pay for the additional instances) or add a cache to the existing Orchard.Azure.Web instance. This shows the configuration using the existing Orchard.Azure.Web role.

Either way, after adding the cache, add an endpoint to the role that is hosting the cache. The endpoint should be internal, use TCP, and be called ‘memcache_default’. I use the 11211 default memcache port, but you can use any valid port. The module looks for the ‘memcache_default’ name when configuring the client and uses whatever port is configured.

Don’t forget to configure the storage for the cache. If you don’t the cache won’t start.

Note that Azure caching does not support Extra Small instances. The back of a napkin math said it was cheaper to host a cache using the unused memory on two small instances also hosting Orchard than to create a single instance of a cache using a small instance and then also host Orchard on two very small instances.

If you deploy using the command line script and you have opted to add a role, then you will also need to change the command that builds the azure package. Open the AzurePackage.proj file in the root of the file structure. Look for the target “package-stage” and add the following parameter to the cspack command (assuming you call your role ‘memcache’):

/role:Memcache;"$(MSBuildProjectDirectory)\src\Orchard.Azure\Memcache\bin\
release";Memcache.dll /rolePropertiesFile:Memcache;"$(CloudRootFolder)\
Properties.txt"

This will add the new role to the package when you build. Next set up your data connection strings and any diagnostics etc. That’s it! Build and go. If you would like to ensure that it is working, please don’t enable the Mini Profiler module. It will break your site when used with this module! (2012-08-27).

You can telnet into the memcache instances by RDPing onto the server and opening a telnet session to the internal endpoint that was set up. The easiest memcache command is ‘stats’ which will show a quick rundown of what is in use.

STAT pid 21892
STAT uptime 60
STAT time 1346100377
STAT version 1.3
STAT pointer_size 64
STAT rusage_user 5.9436381
STAT rusage_system 0.4212027
STAT curr_connections 17
STAT total_connections 17
STAT curr_items 42
STAT bytes 43008
STAT cmd_get 86
STAT cmd_set 42
STAT get_hits 42
STAT get_misses 44
STAT bytes_read 44945
STAT bytes_written 27554
STAT limit_maxbytes 1029701632
END

Subjective testing on a test site yielded very good results with the module running. Complex pages (> 7 fields) were rendering < 400ms using the browser developer mode timings, which was a huge increase over the original 2-3s timings.

Add a Comment

Add a Comment