Skip to content

Commit

Permalink
Add sychronous constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Feb 23, 2023
1 parent 7e974f2 commit 69b9c61
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,27 @@ object MemoryCache {
Resource.make(runExpiration(memoryCache).start)(_.cancel).void
}

/**
* Cache construction is Synchronous
*
* Otherwise a copy paste of {@link #ofSingleImmutableMap() ofSingleImmutableMap}
*
**/
def ofSingleImmutableMap2[G[_] : Sync, F[_]: Async, K, V](
defaultExpiration: Option[TimeSpec]
): G[MemoryCache[F, K, V]] =
Ref.in[G, F, Map[K, MemoryCacheItem[V]]](Map.empty[K, MemoryCacheItem[V]])
.map(ref => new MemoryCache[F, K, V](
MapRef.fromSingleImmutableMapRef(ref),
{(l: Long) => SingleRef.purgeExpiredEntries[F,K, MemoryCacheItem[V]](ref, isExpired)(l)}.some,
defaultExpiration,
{(_, _) => Concurrent[F].unit},
{(_, _) => Concurrent[F].unit},
{(_: K) => Concurrent[F].unit},
{(_: K) => Concurrent[F].unit}
))


/**
* Create a new cache with a default expiration value for newly added cache items.
*
Expand Down

0 comments on commit 69b9c61

Please sign in to comment.