Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matsumotory/mruby-localmemcache
Mruby Inter Process Share Memory. Exchange memory space with mmap for multi mruby process.
https://github.com/matsumotory/mruby-localmemcache
Last synced: about 2 months ago
JSON representation
Mruby Inter Process Share Memory. Exchange memory space with mmap for multi mruby process.
- Host: GitHub
- URL: https://github.com/matsumotory/mruby-localmemcache
- Owner: matsumotory
- License: other
- Created: 2016-03-30T15:27:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-19T06:19:50.000Z (almost 2 years ago)
- Last Synced: 2024-10-18T18:25:27.191Z (3 months ago)
- Language: C
- Homepage:
- Size: 65.4 KB
- Stars: 7
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mruby-localmemcache [![Build Status](https://travis-ci.org/matsumotory/mruby-localmemcache.png?branch=master)](https://travis-ci.org/matsumotory/mruby-localmemcache)
it's based on [localmemcache](https://github.com/sck/localmemcache).
## Install
It's mrbgems.
When you use in your project, please add below to your ``build_config.rb``.
```ruby
conf.gem :github => 'matsumoto-r/mruby-localmemcache'
```## Test
```
rake test
```## Description
```ruby
#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```ruby
cache["key"] = "value"
cache.set "key", "value"
cache["key"] # => "value"
cache.get "key" # => "value"
```see `test/cache.rb`
```ruby
$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'
endassert('get value') do
assert_equal $cache_x['test'], $cache_y['test']
endassert('shm_status keys') do
status = $cache_x.shm_status
assert_equal status.keys.sort, [:free_bytes, :free_chunks, :largest_chunk, :total_bytes, :used_bytes]
endassert('delete key') do
assert_true $cache_x.delete('test')
assert_false $cache_y.delete('test')
endassert('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:
- see [LICENSE file](/LICENSE)