# Localmemcache-0.2.1: The beauty of memcached. For local data. Blazingly fast

**URL:** <https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777>\
**Category:** Ruby\
**Created:** [April 5, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777 "2009-04-05T20:55:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 5, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/1 "2009-04-05T20:55:45Z")

</div>

Hi,

this release addresses some bugs that people were experiencing and  
brings  
speed improvements.

===

Localmemcache that aims to provide an interface similar to memcached but  
for  
accessing local data instead of remote data. It’s based on mmap()'ed  
shared memory for maximum speed.

- [http://localmemcache.rubyforge.org/](http://localmemcache.rubyforge.org/)

===

Changes for 0.2.1:

- Fixed a bug that prevented setting values in the hashtable

- Accessing a closed memory cache does no longer result in a crash

- Speed improvements: On my machine localmemcache is now only about  
20%  
slower than Ruby’s hash (0.2.0 was about 40% slower)

- OS X is now officially not supported as it lacks sem\_timedwait and  
sem\_getvalue (You still can force a build but it won’t be able to  
recover from crashes.)

- The environment variable LMC\_NAMESPACES\_ROOT\_PATH can now be used to  
override the default, which is /var/tmp/localmemcache

# EXAMPLE

require ‘localmemcache’  
$lm = LocalMemCache.new :namespace =\> “viewcounters”  
$lm[:foo] = 1  
$lm[:foo]  
$lm.delete(:foo)

# INSTALL

# gem install localmemcache

(In case rubyforge has not yet updated the mirrors, fetch the 0.2.1 gem  
from here: [http://github.com/sck/localmemcache/downloads](http://github.com/sck/localmemcache/downloads) and then do

# gem install localmemcache-0.2.1.gem )

# CONTACT

Please contact me with bugs, suggestions and patches at: schween + snafu

# de

# LINKS

Localmemcache: [http://localmemcache.rubyforge.org/](http://localmemcache.rubyforge.org/)  
Rubyforge project: [http://localmemcache.rubyforge.org/](http://localmemcache.rubyforge.org/)

Source code is hosted on github: [GitHub - sck/localmemcache: mmap -\> lmc\_valloc -\> hashtable. BAM database](http://github.com/sck/localmemcache/)

Best,

Sven C. Koehler

4e25d2a677e6723f706d47da4dfd68cd localmemcache-0.2.1.gem  
1658b6d660d64dbf57642789f49875e7 localmemcache-0.2.1.tar.gz

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 5, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/2 "2009-04-05T21:33:50Z")

</div>

El Domingo 05 Abril 2009, Sven C. Koehler  
escribió:\> Hi,

> this release addresses some bugs that people were experiencing and brings  
> speed improvements.

Hi, I’m trying to install it in my 64 bits Ubuntu host with Ruby1.9.1  
installed from sources in /usr/local.

This is the error output I get after doing “gem install localmemcache”:

/usr/local/bin/ruby1.9 extconf.rb install localmemcache  
checking for main() in -lrt… \*\*\* extconf.rb failed \*\*\*  
Could not create Makefile due to some reason, probably lack of  
necessary libraries and/or headers. Check the mkmf.log file for more  
details. You may need configuration options.

Provided configuration options:  
–with-opt-dir  
–without-opt-dir  
–with-opt-include  
–without-opt-include=${opt-dir}/include  
–with-opt-lib  
–without-opt-lib=${opt-dir}/lib  
–with-make-prog  
–without-make-prog  
–srcdir=.  
–curdir  
–ruby=/usr/local/bin/ruby1.9  
–with-rtlib  
–without-rtlib  
/usr/local/lib/ruby1.9/1.9.1/mkmf.rb:362:in `try_do': The complier failed to generate an executable file. (RuntimeError) You have to install development tools first. from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:415:in`try\_link0’  
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:419:in `try_link' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:527:in`try\_func’  
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:723:in `block in have_library' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:668:in`block in  
checking\_for’  
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:274:in `block (2 levels) in postpone' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:248:in`open’  
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:274:in `block in postpone' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:248:in`open’  
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:270:in `postpone' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:667:in`checking\_for’  
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:718:in `have_library' from extconf.rb:13:in`’

mkmf.log is empty. What could I check?  
Thanks.

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 5, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/3 "2009-04-05T21:50:14Z")

</div>

El Domingo 05 Abril 2009, Sven C. Koehler  
escribió:\> Hi,

> this release addresses some bugs that people were experiencing and brings  
> speed improvements.

Now I’ve installed it in Ruby1.8 with no problem but I think there is  
something wrong in the Gem.

Basically if I do:

* * *

## ~# irb1.8 irb\> require “localmemcache” LoadError: no such file to load – localmemcache from (irb):5:in `require’ from (irb):5

It makes sense since there is no “lib/localmemcache.rb” in the  
localmemcache  
gem directory.

The only way to load it is by doing:

* * *

## ~# cd /usr/lib/ruby/gems/1.8/gems/localmemcache-0.2.1/src/ruby-binding/ ~# irb1.8 irb\> require “localmemcache” true

I understand that, for a normal Gem to work properly, it must create a  
“gen\_name.rb” in “GEMS\_DIR/gen\_name/lib/” (this is how all the rest of  
Gems  
are installed), but localmemcache doesn’t create a “lib” directory.

Regards.

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 6, 2009, 2:28am UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/4 "2009-04-06T02:28:05Z")

</div>

On Sun, Apr 05, 2009 at 09:48:26PM +0200, Iñaki Baz C. wrote:

> ```
> from (irb):5
> 
> ```

I just checked it with my ubuntu machine and it’s fine for me. Most  
likely you didn’t load rubygems properly:

| sck@u:~/$ sudo gem install localmemcache  
| Building native extensions. This could take a while…  
| Successfully installed localmemcache-0.2.1  
| 1 gem installed  
| sck@u:~$ irb -rubygems  
| irb(main):001:0\> require ‘localmemcache’  
| =\> true  
| irb(main):003:0\> $:  
| =\> ["/var/lib/gems/1.8/gems/localmemcache-0.2.1/bin", “/var/lib/gems/1.8/gems/localmemcache-0.2.1/src/ruby-binding”, “/usr/local/lib/site\_ruby/1.8”, “/usr/local/lib/site\_ruby/1.8/i486-linux”, “/usr/local/lib/site\_ruby/1.8/i386-linux”, “/usr/local/lib/site\_ruby”, “/usr/lib/ruby/vendor\_ruby/1.8”, “/usr/lib/ruby/vendor\_ruby/1.8/i486-linux”, “/usr/lib/ruby/vendor\_ruby”, “/usr/lib/ruby/1.8”, “/usr/lib/ruby/1.8/i486-linux”, “/usr/lib/ruby/1.8/i386-linux”, “.”]

## -S.

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 6, 2009, 2:34am UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/5 "2009-04-06T02:34:30Z")

</div>

El Lunes 06 Abril 2009, David M.  
escribió:\> On Sunday 05 April 2009 14:48:28 Iñaki Baz C. wrote:

> > ~# irb1.8  
> > irb\> require “localmemcache”
> 
> 1.9 has gems loaded by default. 1.8 doesn’t. Try:
> 
> require ‘rubygems’  
> require ‘localmemcache’

Sure you are right. Thanks for pointing it out.

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 6, 2009, 2:36am UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/6 "2009-04-06T02:36:16Z")

</div>

El Lunes 06 Abril 2009, Sven C. Koehler  
escribió:\> I just checked it with my ubuntu machine and it’s fine for me. Most

> likely you didn’t load rubygems properly:

Yes, sorry, I forgot to load rubygems in 1.8.

But there is still the issue with Ruby 1.9.1. It’s a different issue.

Thanks.

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 6, 2009, 2:27am UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/7 "2009-04-06T02:27:29Z")

</div>

On Sunday 05 April 2009 14:48:28 Iñaki Baz C. wrote:

> ~# irb1.8  
> irb\> require “localmemcache”

1.9 has gems loaded by default. 1.8 doesn’t. Try:

require ‘rubygems’  
require ‘localmemcache’

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 6, 2009, 3:48am UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/8 "2009-04-06T03:48:24Z")

</div>

On Mon, Apr 06, 2009 at 09:30:12AM +0900, Iñaki Baz C. wrote:

> But there is still the issue with Ruby 1.9.1. It’s a different issue.

Ok, I just released localmemcache-0.2.2 which should fix the problems  
with Ruby 1.9.

| sck@u:~$ sudo gem install localmemcache  
| Building native extensions. This could take a while…  
| Successfully installed localmemcache-0.2.2  
| 1 gem installed  
| sck@u:~$ irb  
| irb(main):001:0\> require ‘localmemcache’  
| =\> true  
| irb(main):002:0\> $:  
| =\> ["/var/lib/gems/1.9.0/gems/localmemcache-0.2.2/src/ruby-binding", “/var/lib/gems/1.9.0/gems/localmemcache-0.2.2/bin”, “/usr/local/lib/site\_ruby/1.9.0”, “/usr/local/lib/site\_ruby/1.9.0/i486-linux”, “/usr/local/lib/site\_ruby/1.9/i386-linux”, “/usr/local/lib/site\_ruby”, “/usr/lib/ruby/vendor\_ruby/1.9.0”, “/usr/lib/ruby/vendor\_ruby/1.9.0/i486-linux”, “/usr/lib/ruby/vendor\_ruby”, “/usr/lib/ruby/1.9.0”, “/usr/lib/ruby/1.9.0/i486-linux”, “/usr/lib/ruby/1.9/i386-linux”, “.”]

-S.

---

<div class="post-metadata">

**Author:** ![Sven\_CSKoehler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@Sven\_CSKoehler](https://www.ruby-forum.com/u/Sven_CSKoehler)\
**Post date:** [April 6, 2009, 10:38am UTC](https://www.ruby-forum.com/t/localmemcache-0-2-1-the-beauty-of-memcached-for-local-data-blazingly-fast/164777/9 "2009-04-06T10:38:29Z")

</div>

2009/4/6 Sven C. Koehler [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Mon, Apr 06, 2009 at 09:30:12AM +0900, IÃ±aki Baz C. wrote:
> 
> > But there is still the issue with Ruby 1.9.1. It’s a different issue.
> 
> Ok, I just released localmemcache-0.2.2 which should fix the problems  
> with Ruby 1.9.

Thanks, it works!

Just a question: Every data I save in localmemcache is converted to  
String:

irb\> lm[:aaa]=true  
true  
irb\> lm[:bbb]=123  
123  
irb\> lm[:aaa]  
“true”  
irb\> lm[:bbb]  
“123”

About the performance, even if localmemcache is just 20% slower than  
Ruby Hash, I wonder which is the real performance taking into account  
that all the returned values are String, so instead of:

if @do\_action

I must do:

if $lm[:do\_action] == “true”

However, really thanks for this great utility. It allows for example  
running 4 different processes of a Ruby programm in a quad-core CPU  
sharing local memory 🙂
