Giter Site home page Giter Site logo

marianoguerra / rscbag Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 169 KB

Erlang library to store resources in a simple memory kv store with plugable kv implementations and init them on get if not found

License: Mozilla Public License 2.0

Makefile 13.47% Erlang 86.53%

rscbag's Introduction

Resource Bag

An Erlang library to hold a bag of resources, get them by key and initialize them and store them on get if not found.

The store and the resouce life cycle can be parameterized, we provide a default store using ets (default) and another one using gb_trees for your convenience.

Concepts

Store

a simple key value store that holds for each key a reference to a resource, it can put/get/remove and remove_by_value.

Resource Handler

a simple behaviour that provides logic to init and stop your resource, you have to provide this since we don't know what kind of resources you want to handle.

see test/test_resource_handler.erl for a simple example that initializes a resource that is simply the Opts passed to it during init.

Usage

You have to have a module that manages your resources, it must implement two functions:

init(opts()) -> {ok, state()} | {error, reason()}.
stop(state()) -> ok | {error, reason()}.

then create an instance of rscbag:

{ok, Bag} = rscbag_server:start_link(Opts),

where Opts is a proplist with one required key and one optional one:

  • resource_handler (Required): an atom with the name of the module that implements init/1, stop/1
  • kv_mod (Optional, defaults to rscbag_ets): an atom with the name of the module that will be used as kv store for the resources, there are two implemented in this library, rscbag_ets and rscbag_gb_trees, you can implement your own by implemented the rscbag_store behaviour.

then you can use the rscbag API to get, get_existing, remove, remove_by_val, clean, stop etc.

License

MPL 2.0, see LICENSE

rscbag's People

Contributors

marianoguerra avatar

Stargazers

Leonardo Rossi avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.