holmusk / timed-cache / TimedCache

A module to help manage accessing values that are obtained remotely and are accessed more often than they are fetched

An example of this is maybe the notification count on your social feed which is a value you would need to fetch over HTTP and need in multiple places but might not want to fetch as often as you use it.


type alias Model e a =
{ value : a
, maxAge : Basics.Int
, errors : List e
, lastFetched : Maybe Time.Posix
, fetch : Task e a 
}


type Msg e a

init : Task e a -> Basics.Int -> a -> ( Model e a, Platform.Cmd.Cmd (Msg e a) )

Create the initial model and cmds

The arguments in order are: + The task to fetch your value + The maxAge; how old can a value get before needing to be refreshed. In ms + An initial value

update : Model e a -> Msg e a -> ( Model e a, Platform.Cmd.Cmd (Msg e a) )

sub : Model e a -> Platform.Sub.Sub (Msg e a)

clearErrors : Msg e a