GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hyperimpose/polycache: Polycache is a KVS cache that uses ETS and hashes.

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
COPYING
COPYING
 
 
README.org
README.org
 
 
rebar.config
rebar.config
 
 
rebar.lock
rebar.lock
 
 

Repository files navigation

polycache

Polycache is a KVS cache that uses ETS and hashes.

It works like a KVS store, but each key is hashed. When a hash collision occures the previous value is replaced.

Polycache is built on top of ETS. Insertions and lookups go directly to ETS without any serialization or locking. This allows concurrent access without bottlenecks.

Projects using this library should implement locking based on their specific requirements.

Build

Polycache is built using rebar3.

You can include it in your projects as a dependency in rebar.config:

{deps, [%% ... Other dependencies
       {polycache, {git, "https://github.com/hyperimpose/polycache.git", {branch, "master"}}}]}.

or compile it by running $ rebar3 compile

API Usage

The polycache module contains the API that should be used by other programs.

Three functions are exported by polycache: new/1, get/2, set/3, set/4.

%% First, make sure that the application has been started.
application:start(polycache).

%% Create a new cache with: new(Size)
%%
%% Size is the maximum number of elements allowed in the cache.
%% The function returns a reference to the new cache.
Cache = polycache:new(1_000_000).

%% Insert a new entry to the cache: set(Cache, Key, Value).
polycache:set(Cache, key, 5).

%% You can also set an expiration timestamp for this entry. If get/2
%% is called after the entry has expired not_found will be returned.
Ttl = erlang:system_time(seconds) + 300.  % Expires in 5 minutes
polycache:set(Cache, key, 5, #{ttl => Ttl}).

%% Retrieve a value from the cache.
case polycache:get(Cache, key) of
    {ok, Hit} -> Hit;       % Hit is the value saved in the cache
    not_found -> not_found  % No value has been set for this key
end.

Future work

  • Polycache can be extended to work accross multiple nodes by sharing the contents

of each local cache.

  • Two ETS tables could be used for each cache similarly to the 2-random algorithm.

License

polycache is licensed under the BSD 3-Clause “New” or “Revised” License. A copy of this license is included in the file COPYING.

About

Polycache is a KVS cache that uses ETS and hashes.

Topics

cachecache-storageerlangerlang-librarieserlang-libraryerlang-otphashhash-functionshashing

Resources

Readme
License
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.