aboutsummaryrefslogtreecommitdiff
path: root/lib/cache.mli
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-03-06 10:41:18 -0700
committerAdelyn Breedlove <[email protected]>2019-03-06 10:41:18 -0700
commitf68838306a66cb358688f4976c5770db89293db4 (patch)
treebdd6388df7f0fbf9c7512485e91da83a7ec47821 /lib/cache.mli
parentClose frames should log code now (diff)
downloaddisml-f68838306a66cb358688f4976c5770db89293db4.tar.xz
disml-f68838306a66cb358688f4976c5770db89293db4.zip
Unfuck the cache
Diffstat (limited to 'lib/cache.mli')
-rw-r--r--lib/cache.mli36
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/cache.mli b/lib/cache.mli
index 7a76b57..bebaef1 100644
--- a/lib/cache.mli
+++ b/lib/cache.mli
@@ -7,10 +7,10 @@ module GuildMap : module type of Map.Make(Guild_id_t)
(** Represents a Map of {!User_id.t} keys. *)
module UserMap : module type of Map.Make(User_id_t)
-(** The full cache record. Immutable and intended to be wrapped in a concurrency-safe wrapper such as {{!Async.Mvar.Read_write.t}Mvar}.
+(** The full cache record. Immutable and intended to be wrapped in a concurrency-safe wrapper.
Channels are split by type so it isn't necessary to match them later on.
*)
-type t =
+type cache =
{ text_channels: Channel_t.guild_text ChannelMap.t
; voice_channels: Channel_t.guild_voice ChannelMap.t
; categories: Channel_t.category ChannelMap.t
@@ -24,8 +24,11 @@ type t =
; users: User_t.t UserMap.t
}
-(** A {{!t}cache} wrapped in an {{!Async.Mvar.Read_write.t}Mvar}. *)
-val cache : t Lwt_mvar.t
+(** An opaque container around a mutex and cache *)
+type t
+
+(** A global t that the lib keeps up to date. You can always keep your own cache with this implementation with {!create}. *)
+val cache : t
(** Creates a new, empty cache. *)
val create :
@@ -33,44 +36,55 @@ val create :
unit ->
t
+(** [update t f] locks t and calls f with the internal cache, then writes the result to the cache. *)
+val update :
+ t ->
+ (cache -> cache) ->
+ unit Lwt.t
+
+(** [read_copy t] awaits the lock on t, then returns a copy of the internal cache before unlocking. *)
+val read_copy :
+ t ->
+ cache Lwt.t
+
(** Equivalent to {!GuildMap.find} on cache.guilds. *)
val guild :
Guild_id_t.t ->
- t ->
+ cache ->
Guild_t.t option
(** Equivalent to {!ChannelMap.find} on cache.text_channels. *)
val text_channel :
Channel_id_t.t ->
- t ->
+ cache ->
Channel_t.guild_text option
(** Equivalent to {!ChannelMap.find} on cache.voice_channels. *)
val voice_channel :
Channel_id_t.t ->
- t ->
+ cache ->
Channel_t.guild_voice option
(** Equivalent to {!ChannelMap.find} on cache.categories. *)
val category :
Channel_id_t.t ->
- t ->
+ cache ->
Channel_t.category option
(** Equivalent to {!ChannelMap.find} on cache.private_channels. *)
val dm :
Channel_id_t.t ->
- t ->
+ cache ->
Channel_t.dm option
(** Equivalent to {!ChannelMap.find} on cache.groups. *)
val group :
Channel_id_t.t ->
- t ->
+ cache ->
Channel_t.group option
(** Helper method that scans all channel stores and returns a {!Channel.t} holding the channel. *)
val channel :
Channel_id_t.t ->
- t ->
+ cache ->
Channel_t.t option \ No newline at end of file