Install memcached in Mac OS and using it in Perl

memcached is quite powerful but easy to use caching system. I would suggest you to read this wonderful story https://code.google.com/p/memcached/wiki/TutorialCachingStory to make you understand how it works.

To install memcached in Mac os we going to use brew. You can follow http://blog.jambura.com/2013/02/19/setup-homebrew-perlbrew-ruby-rvm-perl-cpanm-nginx-in-mountain-lion/ to install brew.

brew update
brew install memcached

Then add memcached to launchctl

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

You can run as daemon also

memcached -l 127.0.0.1 -p 11211 -d

There two Perl library I found Cache::Memcached::Fast and Cache::Memcached. While using Cache::Memcached I found this error “Storable binary image v48.98 more recent than I am (v2.8)”. Which is happening in Storable.pm line 417. While searching for solution, I found its much harder to fix. So its better to use Cache::Memcached::Fast. Its quite easy to use.

my $memd = new Cache::Memcached::Fast{servers => [$self->memd_server], compress_threshold => 100_000};
my $sub_tree_path = 'cat/car', my $attr = [1,2,3];
$memd->set($sub_tree_path, $attr);
my $memd_attr = $memd->get($sub_tree_path);

About Zakir Hyder

This entry was written by .

26. November 2013 by Zakir Hyder
Categories: Caching, Perl | Tags: , , , , | Comments