-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version = 3.7.7 | ||
version = 3.8.0 | ||
runner.dialect = scala3 | ||
lineEndings = unix | ||
importSelectors = singleLine | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package manjuu.client | ||
|
||
import cats.effect.kernel.{Async, Resource} | ||
import dev.profunktor.redis4cats.Redis | ||
import dev.profunktor.redis4cats.codecs.Codecs | ||
import dev.profunktor.redis4cats.codecs.splits.SplitEpi | ||
import dev.profunktor.redis4cats.data.RedisCodec | ||
import dev.profunktor.redis4cats.effect.Log.Stdout.given | ||
import io.circe.{Json, JsonObject} | ||
import io.circe.parser.{decode => jsonDecode} | ||
import io.circe.syntax._ | ||
import org.http4s.headers.`Access-Control-Max-Age`.Cache | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
trait Cache[F[_], K, V]: | ||
def get(key: K): F[Option[V]] | ||
def set(key: K, value: V): F[Unit] | ||
|
||
object Cache: | ||
val eventSplitEpi: SplitEpi[String, Json] = | ||
SplitEpi[String, Json]( | ||
str => jsonDecode(str).getOrElse(JsonObject.empty.asJson), | ||
_.asJson.noSpaces | ||
) | ||
val jsonCodec = Codecs.derive(RedisCodec.Utf8, eventSplitEpi) | ||
|
||
def redis[F[_]: Async](uri: String, ttl: FiniteDuration): Resource[F, Cache[F, String, Json]] = | ||
Redis[F].simple(uri, jsonCodec).map { | ||
redis => | ||
new Cache[F, String, Json]: | ||
def get(key: String): F[Option[Json]] = redis.get(key) | ||
def set(key: String, value: Json): F[Unit] = redis.setEx(key, value, ttl) | ||
} | ||
|
||
def memory[F[_]: Async]: Resource[F, Cache[F, String, Json]] = | ||
val cache = new Cache[F, String, Json]: | ||
val store = scala.collection.mutable.Map.empty[String, Json] | ||
def get(key: String): F[Option[Json]] = Async[F].pure(store.get(key)) | ||
def set(key: String, value: Json): F[Unit] = Async[F].pure(store.update(key, value)) | ||
|
||
Resource.pure[F, Cache[F, String, Json]](cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 0 additions & 95 deletions
95
server/src/test/scala/manjuu/services/AuthorityServiceSpec.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters