Current section
Files
Jump to
Current section
Files
doc/SimplerCache.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.7</title>
<link rel="stylesheet" href="dist/app-240d7fc7e5.css" />
<link rel="canonical" href="https://hexdocs.pm/simpler_cache/SimplerCache.html" />
<script src="dist/sidebar_items-dd7e682a25.js"></script>
</head>
<body data-type="modules">
<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.7
</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>
<small class="visible-xs">Simpler Cache v0.1.7</small>
SimplerCache
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L1" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</h1>
<section id="moduledoc">
<p>Simple cache implementation with no complicated features or locks.</p>
</section>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
<div class="summary-types summary">
<h2>
<a href="#types">Types</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#t:fallback_function/0">fallback_function()</a>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#t:update_function/0">update_function()</a>
</div>
</div>
</div>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#delete/1">delete(key)</a>
</div>
<div class="summary-synopsis"><p>Deletes item from cache or does no-op</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get/1">get(key)</a>
</div>
<div class="summary-synopsis"><p>Returns an item from cache or nil if not found</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#get_or_store/3">get_or_store(key, fallback_fn, ttl_ms \\ 10000)</a>
</div>
<div class="summary-synopsis"><p>Gets or stores an item based on a passed in function
if the item is near expiry it will also update the cache and ttl to avoid thundering herd issues</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#insert_new/3">insert_new(key, value, ttl_ms \\ 10000)</a>
</div>
<div class="summary-synopsis"><p>Inserts new item into cache</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#put/3">put(key, value, ttl_ms \\ 10000)</a>
</div>
<div class="summary-synopsis"><p>Inserts new item or overwrites old item’s value</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#set_ttl_ms/2">set_ttl_ms(key, time_ms)</a>
</div>
<div class="summary-synopsis"><p>Sets the ttl to a specific value in ms greater than 0 for an item</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#size/0">size()</a>
</div>
<div class="summary-synopsis"><p>Returns the number of elements in the cache</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#update_existing/2">update_existing(key, passed_fn)</a>
</div>
<div class="summary-synopsis"><p>Updates existing value in cache based on old value and resets the timer
Warning the below may retry a bit on heavy contention</p>
</div>
</div>
</div>
</section>
<section id="types" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#types">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Types
</h1>
<div class="types-list">
<div class="detail" id="t:fallback_function/0">
<div class="detail-header">
<a href="#t:fallback_function/0" class="detail-link" title="Link to this type">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this type</span>
</a>
<span class="signature">fallback_function()</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L10" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>fallback_function() :: (() -> <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>())</pre>
</div>
</div>
<section class="docstring">
</section>
</div>
<div class="detail" id="t:update_function/0">
<div class="detail-header">
<a href="#t:update_function/0" class="detail-link" title="Link to this type">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this type</span>
</a>
<span class="signature">update_function()</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L9" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>update_function() :: (<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>() -> <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>())</pre>
</div>
</div>
<section class="docstring">
</section>
</div>
</div>
</section>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Functions
</h1>
<div class="detail" id="delete/1">
<div class="detail-header">
<a href="#delete/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">delete(key)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L67" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>delete(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()) :: {:ok, :deleted} | {:ok, :not_found}</pre>
</div>
</div>
<section class="docstring">
<p>Deletes item from cache or does no-op</p>
</section>
</div>
<div class="detail" id="get/1">
<div class="detail-header">
<a href="#get/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">get(key)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L16" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>get(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()) :: nil | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()</pre>
</div>
</div>
<section class="docstring">
<p>Returns an item from cache or nil if not found</p>
</section>
</div>
<div class="detail" id="get_or_store/3">
<span id="get_or_store/2"></span>
<div class="detail-header">
<a href="#get_or_store/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">get_or_store(key, fallback_fn, ttl_ms \\ 10000)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L99" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>get_or_store(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="#t:fallback_function/0">fallback_function</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">pos_integer</a>()) :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()</pre>
</div>
</div>
<section class="docstring">
<p>Gets or stores an item based on a passed in function
if the item is near expiry it will also update the cache and ttl to avoid thundering herd issues</p>
</section>
</div>
<div class="detail" id="insert_new/3">
<span id="insert_new/2"></span>
<div class="detail-header">
<a href="#insert_new/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">insert_new(key, value, ttl_ms \\ 10000)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L46" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>insert_new(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">pos_integer</a>()) ::
{:ok, :inserted} | {:error, :item_is_in_cache} | {:error, <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()}</pre>
</div>
</div>
<section class="docstring">
<p>Inserts new item into cache</p>
</section>
</div>
<div class="detail" id="put/3">
<span id="put/2"></span>
<div class="detail-header">
<a href="#put/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">put(key, value, ttl_ms \\ 10000)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L33" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>put(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">pos_integer</a>()) :: {:ok, :inserted} | {:error, <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()}</pre>
</div>
</div>
<section class="docstring">
<p>Inserts new item or overwrites old item’s value</p>
</section>
</div>
<div class="detail" id="set_ttl_ms/2">
<div class="detail-header">
<a href="#set_ttl_ms/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">set_ttl_ms(key, time_ms)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L141" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>set_ttl_ms(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">pos_integer</a>()) ::
{:ok, :updated}
| {:error, :failed_to_update_element}
| {:error, :element_not_found}
| {:error, <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()}</pre>
</div>
</div>
<section class="docstring">
<p>Sets the ttl to a specific value in ms greater than 0 for an item</p>
</section>
</div>
<div class="detail" id="size/0">
<div class="detail-header">
<a href="#size/0" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">size()</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L131" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>size() :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">non_neg_integer</a>()</pre>
</div>
</div>
<section class="docstring">
<p>Returns the number of elements in the cache</p>
</section>
</div>
<div class="detail" id="update_existing/2">
<div class="detail-header">
<a href="#update_existing/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">update_existing(key, passed_fn)</span>
<a href="https://github.com/IRog/simpler_cache/blob/master/lib/simpler_cache.ex#L83" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<div class="specs">
<pre>update_existing(<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), <a href="#t:update_function/0">update_function</a>()) ::
{:ok, :updated} | {:error, :failed_to_find_entry}</pre>
</div>
</div>
<section class="docstring">
<p>Updates existing value in cache based on old value and resets the timer
Warning the below may retry a bit on heavy contention</p>
</section>
</div>
</section>
<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>