Packages

A simple cache with ttl based on ets and timers. Tested with property model testing. Thundering herd fix, as well

Current section

Files

Jump to
simpler_cache doc readme.html
Raw

doc/readme.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.19.1">
<title>SimplerCache – Simpler Cache v0.1.6</title>
<link rel="stylesheet" href="dist/app-240d7fc7e5.css" />
<link rel="canonical" href="https://hexdocs.pm/simpler_cache/readme.html" />
<script src="dist/sidebar_items-e06293932b.js"></script>
</head>
<body data-type="extras">
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
<div class="main">
<button class="sidebar-button sidebar-toggle">
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
<span class="icon-theme" aria-hidden="true"></span>
<span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">
<a href="https://github.com/IRog/simpler_cache" class="sidebar-projectLink">
<div class="sidebar-projectDetails">
<h1 class="sidebar-projectName">
Simpler Cache </h1>
<h2 class="sidebar-projectVersion">
v0.1.6
</h2>
</div>
</a>
<form class="sidebar-search" action="search.html">
<button type="submit" class="search-button">
<span class="icon-search" aria-hidden="true"></span>
</button>
<input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
</form>
<ul class="sidebar-listNav">
<li><a id="extras-list" href="#full-list">Pages</a></li>
<li><a id="modules-list" href="#full-list">Modules</a></li>
</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
</section>
<section class="content">
<div class="content-outer">
<div id="content" class="content-inner">
<h1>SimplerCache</h1>
<p><a href="https://travis-ci.com/IRog/simpler_cache"><img src="https://travis-ci.com/IRog/simpler_cache.svg?branch=master" alt="Build Status"/></a>
<a href="https://coveralls.io/github/IRog/simpler_cache?branch=master"><img src="https://coveralls.io/repos/github/IRog/simpler_cache/badge.svg?branch=master" alt="Coverage Status"/></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"/></a>
<a href="https://hex.pm/packages/simpler_cache"><img src="http://img.shields.io/hexpm/v/simpler_cache.svg?style=flat" alt="Hex pm"/></a>
<a href="https://hexdocs.pm/simpler_cache/"><img src="https://img.shields.io/badge/docs-latest-green.svg?style=flat" alt="hexdocs.pm"/></a></p>
<h2 id="description" class="section-heading">
<a href="#description" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Description
</h2>
<p>A very simple cache. It uses timers for the ttl and ets for the storage. No locks are used and there is a fix to prevent thundering herd issues and pre-emptively refresh the cache (it triggers in low ttl left of item situations).
Mostly wrapper around ets and kept very simple by using newer apis and recent erlang improvements.</p>
<p>Using property model testing and property tests to verify the cache via propcheck.</p>
<h2 id="installation" class="section-heading">
<a href="#installation" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Installation
</h2>
<p><a href="https://hex.pm/packages/simpler_cache">available in Hex</a>, the package can be installed
by adding <code class="inline">simpler_cache</code> to your list of dependencies in <code class="inline">mix.exs</code>:</p>
<pre><code class="nohighlight makeup elixir"><span class="kd">def</span><span class="w"> </span><span class="nf">deps</span><span class="w"> </span><span class="k" data-group-id="3545512490-1">do</span><span class="w">
</span><span class="p" data-group-id="3545512490-2">[</span><span class="w">
</span><span class="p" data-group-id="3545512490-3">{</span><span class="ss">:simpler_cache</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;~&gt; 0.1.5&quot;</span><span class="p" data-group-id="3545512490-3">}</span><span class="w">
</span><span class="p" data-group-id="3545512490-2">]</span><span class="w">
</span><span class="k" data-group-id="3545512490-1">end</span></code></pre>
<ul>
<li>Sample configs
</li>
</ul>
<pre><code class="nohighlight makeup elixir"><span class="n">config</span><span class="w"> </span><span class="ss">:simpler_cache</span><span class="p">,</span><span class="w">
</span><span class="ss">cache_name</span><span class="p">:</span><span class="w"> </span><span class="ss">:simpler_cache_test</span><span class="p">,</span><span class="w">
</span><span class="ss">global_ttl_ms</span><span class="p">:</span><span class="w"> </span><span class="mi">100_000</span></code></pre>
<h3 id="100-processes-concurrently-hitting-cache-on-1-key-with-get_or_store" class="section-heading">
<a href="#100-processes-concurrently-hitting-cache-on-1-key-with-get_or_store" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
100 processes concurrently hitting cache on 1 key with get_or_store
</h3>
<p><img src="https://github.com/IRog/simpler_cache/blob/benchmark/images/100_iterations.png" alt="iterations"/></p>
<p><img src="https://github.com/IRog/simpler_cache/blob/benchmark/images/100_runtime.png" alt="runtime"/></p>
<footer class="footer">
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener">ExDoc</a> (v0.19.1),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-a0c90688fa.js"></script>
</body>
</html>