time-cache

Cache current time and formatted time text

http://rel4tion.org/projects/time-cache

Latest on Hackage:0.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

LicenseRef-PublicDomain licensed by fr33domlover
Maintained by [email protected]

Suppose you have an IO action which runs very frequently, and one of the things it does is getting the current UTCTime, possibly also formatting it into a String or Text. The action cares about the current minute, and doesn't care about seconds or milliseconds at all. Instead of reading and formatting the time many times, using this library you can keep a cache which updates every minute (or other interval) and allows your application to scale without time reading and formatting ever becoming a bottleneck.

There are 2 modules provided. I suggest you start with the monadic one, especially for simple usage, and switch to the other one if you need some custom solution.

The Data.Time.Cache module allows you to create a time caching action which returns time and a formatted time string. But instead of directly reading the time and running a formatter, it takes the values from a cache it periodically updates.

The Control.Monad.Trans.Time module provides a convenient monadic wrapper for the time cache.

If you need the time cache in multiple threads, you can create the time getter once and then pass to all the threads to share.