1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Make(IO : S.IO)(Client : S.Client with module IO = IO)(Params : S.Cache_params) = struct
module IO = IO
module Client = Client
module Params = Params
let (>>=) = IO.(>>=)
let set r key data =
let key = Params.cache_key key in
let data = Params.string_of_data data in
Client.set r key data >>= fun _ ->
IO.return (Utils.Option.may
(fun cache_expiration ->
IO.ignore_result (Client.expire r key cache_expiration)
)
Params.cache_expiration)
let get r key =
let key = Params.cache_key key in
Client.get r key >>= fun value ->
IO.return (Utils.Option.map Params.data_of_string value)
let delete r key =
let key = Params.cache_key key in
IO.ignore_result (Client.del r [key])
end