package sihl-cache

  1. Overview
  2. Docs
Cache service implementations for Sihl

Install

Dune Dependency

Authors

Maintainers

Sources

3.0.0.tar.gz
md5=3ceaa839d4d9480011761257aedf2f22
sha512=6b44bb6f67b1933a7b74fff8488d3cc6c9a7360fa99b3aeae9158e2887dbc44c1b215d8cffb6cc082cc88a0ffa576b2d9ebdd21850f2a19656aedbe4c0fe2c59

doc/index.html

Sihl Cache

This module provides the cache service and helpers to store arbitrary values. Think of the cache service as a generic key-value store where you can choose a backend.

Currently MariaDb (Sihl_cache.MariaDb) and PostgreSql (Sihl_cache.PostgreSql) are supported.

Installation

Backend

First, choose a backend in service/service.ml:

module Cache = Sihl_cache.PostgreSql

Registration

Then, register the service in run/run.ml:

let services = [ Service.Cache.register () ]

Migrations

Run pending migrations with make sihl migrate.

Usage

The API is documented in Sihl.Contract.Cache.Sig.

  
  (* Associated user_id with a value *)
  let%lwt () = Service.Cache.set ("user_id", Some "56") in
  let%lwt user_id = Service.Cache.find "user_id" in
  let () =
    match user_id with
    | Some user_id -> print_endline @@ "Found user " ^ user_id
    | None -> print_endline "No user found"
  (* Delete user_id *)
  Service.Cache.set ("user_id", None)
OCaml

Innovation. Community. Security.