Posts

Showing posts from November, 2021

zio and refilling a cache

zio and refilling a cache In some small web app server projects I sometimes need to cache some data to reduce latency and the impact of queries on a “weak” backend database. We can use alot of clever caching tools but sometimes I just need something quick and dirty. If you are using ZIO-style services, you may want the cache to be independent of other services and maintain the cache internally to the service environment. There are many ways to cache remote data, for example, you could also use ZQuery or the newer ZCache. Let’s assume that we want to do something simple: case class PeopleCache ( byId : Map [ UUID , Person ] = Map ( ) , last : LocalDateTime = LocalDateTime . now ( ) ) object PeopleCache : def createFromList ( people : List [ Person ] ) = ? ? ? trait Service : def search ( qstring : String ) : IO [ Exception , Option [ Person ] val live = ? ? ? class PeopleServiceImpl ( cache : RefM [ PeopleCache ] , db