Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Since memcache stores everything in ram, it will lose its store after a node recovers from failure. Does memcache offer a hook to invoke a script after it starts up? We want that script to do "something", either hit an external service, etc., to reload the cache. We're using Ubuntu 11.

share|improve this question
1  
Memcached is dead simple, and doesn't have that functionality built in. I would just stick something in /etc/rc.local or modify the startup script for memcache to run whatever commands you want. –  cjc May 17 '13 at 14:25
    
Maybe you should have a look at couchbase: couchbase.com/memcached –  symcbean May 17 '13 at 15:50
    
(no /etc/rc.local is not part of memcache - it's a start up script run at the end of the sysV init on POSIX systems - cjc is correct that this would be a good way to populate the cache). –  symcbean May 17 '13 at 15:51
    
assuming its a system that uses a classic sysv init system. This might be simplified using upstart (and I assume, not having used it before) systemd. Mentioning what OS is being used is ESSENTIAL for a good answer IMO –  Journeyman Geek May 17 '13 at 16:58
    
you'll want to edit that into your question. Upstart would help here, but its too late at night for me to make that into a coherent answer. ;p –  Journeyman Geek May 17 '13 at 17:13

2 Answers 2

Memcache is non-persistent cache (the whole idea is to supplement data-providers such as MySQL and cache the most-used data, not replace them altogether), so what you're asking cannot be achieved.

The argument over 'persistent memcache' is a can of worms in itself, as some people maintain that if you build a 'persistent memcache', then it is no longer a 'cache'.

For more details (many more than I can provide here), check out this StackOverflow post.

share|improve this answer
    
I'm not trying to persist memcache data, I just need a way to quickly reload it after it recovers from a failure. –  SAFX May 17 '13 at 14:42
    
That's the very definition of persistence in computing terms: en.wikipedia.org/wiki/Persistence_(computer_science) –  Craig Watson May 17 '13 at 14:47
    
Essentially, memcache data is generated, not loaded - you actually have to make a query, then record the result of that query in the cache. What you're asking is far beyond the realms of memcache by definition ('memory' and 'cache'). –  Craig Watson May 17 '13 at 14:50
    
Craig, I think you're splitting hairs here. We are not replicating memcache data. We use a database for persistence, it's a small data set, so if memcache goes down, it's little effort for us to reload it, if we don't, our users take a performance hit...do you think users care about the difference between generated and loaded? :-) –  SAFX May 17 '13 at 15:18
    
Users obviously shouldn't care, they're users! However, memcache just isn't built for the purpose that you're asking about. Even by name, it's a memory cache. If you're relying on memcache for performance (and it sounds like you are), perhaps you could investigate why the initial performance is so slow and fix that, rather than relying on a technology which was only ever intended to be a performance-boost? –  Craig Watson May 17 '13 at 15:28

Since, you're running Ubuntu, you can wrap memcache tasks into an Upstart configuration.

The "hook" to invoke a script after memcached starts would be in the post-start section of the Upstart configuration.

Your config will then look something like:

# memcached - in-memory cache
#
description "memcached"

start on (local-filesystems and started networking)
stop on runlevel [!2345]

respawn

pre-start script
  test -x /usr/bin/memcached || { stop; exit 0; }
end script

exec /usr/bin/memcached -v -m 64 -p 11211 -u nobody -l 127.0.0.1

post-start script
  /usr/local/bin/populate-memcache.sh
end script

Please check the Upstart documentation, etc. You'll of course need to remove the memcached startup script from /etc/init.d.

share|improve this answer
    
Interesting, will try this out, ty. –  SAFX May 17 '13 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.