Skip to content

Mruby Inter Process Share Memory. Exchange memory space with mmap for multi mruby process.

License

Notifications You must be signed in to change notification settings

matsumotory/mruby-localmemcache

Repository files navigation

mruby-localmemcache Build Status

it's based on localmemcache.

Install

It's mrbgems.

When you use in your project, please add below to your build_config.rb.

  conf.gem :github => 'matsumoto-r/mruby-localmemcache'

Test

rake test

Description

#Creates a new handle for accessing a shared memory region.

cache = Cache.new :namespace=>"foo", :size_mb=> 1
cache = Cache.new :namespace=>"foo", :size_mb=> 1, :min_alloc_size => 256
cache = Cache.new :filename=>"./foo.lmc"
cache = Cache.new :filename=>"./foo.lmc", :min_alloc_size => 512

You must supply at least a :namespace or :filename parameter The size_mb defaults to 1024 (1 GB).

Usage

  • getter and setter
cache["key"] = "value"
cache.set "key", "value"
cache["key"]    # => "value"
cache.get "key" # => "value"

see test/cache.rb

$cache_x = Cache.new :filename =>"./foo.lmc"
$cache_y = Cache.new :filename =>"./foo.lmc"

assert('set value') do
  assert_equal ($cache_x['test']='hello'), 'hello'
end

assert('get value') do
  assert_equal $cache_x['test'], $cache_y['test']
end

assert('shm_status keys') do
  status = $cache_x.shm_status
  assert_equal status.keys.sort, [:free_bytes, :free_chunks, :largest_chunk, :total_bytes, :used_bytes]
end

assert('delete key') do
  assert_true $cache_x.delete('test')
  assert_false $cache_y.delete('test')
end

assert('fetch deleted key') do
  assert_nil $cache_x['test']
  assert_nil $cache_y['test']
end

$cache_x.close
$cache_y.close
Cache.drop :filename =>"./foo.lmc"

Contributing

Feel free to open tickets or send pull requests with improvements. Thanks in advance for your help!

License

under the MIT License:

About

Mruby Inter Process Share Memory. Exchange memory space with mmap for multi mruby process.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published