From 337f3568accc53144ae6db6479570221cb21e7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=A2=83=E8=BF=B7=E7=A6=BB?= Date: Fri, 12 Aug 2022 14:17:33 +0800 Subject: [PATCH 1/3] remove unavailable modules --- README.md | 40 +---- build.sbt | 111 +----------- .../main/scala/org/bitlap/tools/Main.scala | 20 --- .../scala/org/bitlap/tools/CacheExample.scala | 71 -------- .../scala/org/bitlap/tools/CacheValue.scala | 13 -- .../main/scala/org/bitlap/tools/Main.scala | 20 --- .../scala/org/bitlap/tools/CacheExample.scala | 71 -------- .../scala/org/bitlap/tools/CacheValue.scala | 16 -- .../main/scala/org/bitlap/tools/Main.scala | 33 ---- project/plugins.sbt | 1 - .../scala/org/bitlap/tools/LogLevel.scala | 8 +- .../main/scala/org/bitlap/tools/apply.scala | 2 +- .../main/scala/org/bitlap/tools/builder.scala | 2 +- .../scala/org/bitlap/tools/constructor.scala | 2 +- .../main/scala/org/bitlap/tools/elapsed.scala | 2 +- .../org/bitlap/tools/equalsAndHashCode.scala | 2 +- .../AbstractMacroProcessor.scala | 14 +- .../{macros => internal}/applyMacro.scala | 2 +- .../{macros => internal}/builderMacro.scala | 2 +- .../constructorMacro.scala | 2 +- .../{macros => internal}/elapsedMacro.scala | 2 +- .../equalsAndHashCodeMacro.scala | 2 +- .../javaCompatibleMacro.scala | 2 +- .../tools/{macros => internal}/logMacro.scala | 2 +- .../tools/{macros => internal}/macros.scala | 4 +- .../{macros => internal}/toStringMacro.scala | 2 +- .../org/bitlap/tools/javaCompatible.scala | 2 +- .../src/main/scala/org/bitlap/tools/log.scala | 2 +- .../scala/org/bitlap/tools/logs/LogType.scala | 2 +- .../scala/org/bitlap/tools/toString.scala | 2 +- .../src/main/resources/reference.conf | 6 - .../bitlap/cacheable/caffeine/Implicits.scala | 116 ------------ .../bitlap/cacheable/caffeine/ZCaffeine.scala | 106 ----------- .../src/test/resources/application.conf | 5 - .../cacheable/caffeine/CacheEvictTest.scala | 123 ------------- .../cacheable/caffeine/CacheValue.scala | 24 --- .../cacheable/caffeine/CacheableTest.scala | 168 ------------------ .../caffeine/CustomCacheableTest.scala | 57 ------ .../src/main/resources/reference.conf | 5 - .../bitlap/cacheable/redis/Implicits.scala | 111 ------------ .../cacheable/redis/ZRedisConfiguration.scala | 52 ------ .../bitlap/cacheable/redis/ZRedisLive.scala | 49 ----- .../cacheable/redis/ZRedisService.scala | 83 --------- .../org/bitlap/cacheable/redis/redis.scala | 35 ---- .../src/test/resources/application.conf | 5 - .../cacheable/redis/CacheEvictTest.scala | 118 ------------ .../bitlap/cacheable/redis/CacheValue.scala | 31 ---- .../cacheable/redis/CacheableTest.scala | 108 ----------- .../cacheable/redis/CustomCacheableTest.scala | 61 ------- .../org/bitlap/cacheable/core/Cache.scala | 98 ---------- .../org/bitlap/cacheable/core/Utils.scala | 55 ------ .../org/bitlap/cacheable/core/ZIOCache.scala | 41 ----- .../cacheable/core/ZIOUpdateCache.scala | 41 ----- .../bitlap/cacheable/core/ZStreamCache.scala | 39 ---- .../cacheable/core/ZStreamUpdateCache.scala | 40 ----- .../bitlap/cacheable/core/cacheEvict.scala | 42 ----- .../org/bitlap/cacheable/core/cacheable.scala | 40 ----- .../core/macros/AbstractMacroProcessor.scala | 103 ----------- .../core/macros/CacheEvictMacro.scala | 128 ------------- .../core/macros/CacheableMacro.scala | 83 --------- .../org/bitlap/cacheable/core/package.scala | 30 ---- 61 files changed, 36 insertions(+), 2423 deletions(-) delete mode 100644 examples/scala2-11/src/main/scala/org/bitlap/tools/Main.scala delete mode 100644 examples/scala2-12/src/main/scala/org/bitlap/tools/CacheExample.scala delete mode 100644 examples/scala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala delete mode 100644 examples/scala2-12/src/main/scala/org/bitlap/tools/Main.scala delete mode 100644 examples/scala2-13/src/main/scala/org/bitlap/tools/CacheExample.scala delete mode 100644 examples/scala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala delete mode 100644 examples/scala2-13/src/main/scala/org/bitlap/tools/Main.scala rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/AbstractMacroProcessor.scala (97%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/applyMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/builderMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/constructorMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/elapsedMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/equalsAndHashCodeMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/javaCompatibleMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/logMacro.scala (99%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/macros.scala (95%) rename smt-annotations/src/main/scala/org/bitlap/tools/{macros => internal}/toStringMacro.scala (99%) delete mode 100644 smt-cacheable-caffeine/src/main/resources/reference.conf delete mode 100644 smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/Implicits.scala delete mode 100644 smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/ZCaffeine.scala delete mode 100644 smt-cacheable-caffeine/src/test/resources/application.conf delete mode 100644 smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheEvictTest.scala delete mode 100644 smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheValue.scala delete mode 100644 smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheableTest.scala delete mode 100644 smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CustomCacheableTest.scala delete mode 100644 smt-cacheable-redis/src/main/resources/reference.conf delete mode 100644 smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/Implicits.scala delete mode 100644 smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala delete mode 100644 smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisLive.scala delete mode 100644 smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisService.scala delete mode 100644 smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/redis.scala delete mode 100644 smt-cacheable-redis/src/test/resources/application.conf delete mode 100644 smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheEvictTest.scala delete mode 100644 smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheValue.scala delete mode 100644 smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheableTest.scala delete mode 100644 smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CustomCacheableTest.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Cache.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Utils.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOCache.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOUpdateCache.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamCache.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamUpdateCache.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheEvict.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheable.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/AbstractMacroProcessor.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheEvictMacro.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheableMacro.scala delete mode 100644 smt-cacheable/src/main/scala/org/bitlap/cacheable/core/package.scala diff --git a/README.md b/README.md index d8bd57ba..dd875c80 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ 添加库依赖,下面是如何在 SBT 中使用 -> 在gradle,maven中,通常`smt-annotations`被替换为`smt-annotations_2.12`这种。其中,`2.12`表示Scala版本号。 +> 在gradle,maven中,通常`smt-annotations`被替换为`smt-annotations_2.12`,其中,`2.12`表示Scala版本号。 ## cache @@ -51,7 +51,7 @@ - 零依赖,类型安全。 ```scala -"org.bitlap" %% "smt-csv" % "" // 从0.5.2开始 +"org.bitlap" %% "smt-csv" % "" ``` ## csv-derive @@ -59,7 +59,7 @@ - `DeriveCsvConverter` 为Scala`case class`自动派生`Converter`实例。 ```scala -"org.bitlap" %% "smt-csv-derive" % "" // 从0.5.2开始 +"org.bitlap" %% "smt-csv-derive" % "" ``` ## annotations @@ -76,37 +76,7 @@ > Intellij插件 `Scala-Macro-Tools`。 ```scala -"org.bitlap" %% "smt-annotations" % "" // 从0.6.0开始名字改成 smt-annotations -``` - -## cacheable [不可上生产] - -基于zio的类似Spring`@Cacheable`和`@CacheEvict`注解的缓存API定义。该模块不包含具体的存储媒介。 - -- `@cacheable` / `Cache.apply` -- `@cacheEvict` / `Cache.evict` - -```scala -// 内部包含的依赖: zio, zio-streams, zio-logging -"org.bitlap" %% "smt-cacheable" % "" // 不支持Scala2.11.x -``` - -## cacheable-redis [不可上生产] - -基于zio和zio-redis的分布式缓存实现,内部依赖`cacheable`。 - -> TODO,目前不可用 - -```scala -"org.bitlap" %% "smt-cacheable-redis" % "" // 不支持Scala2.11.x -``` - -## cacheable-caffeine [不可上生产] - -基于zio和caffeine的内存缓存实现,内部依赖`cacheable`。(不支持Scala2.11.x) - -```scala -"org.bitlap" %% "smt-cacheable-caffeine" % "" +"org.bitlap" %% "smt-annotations" % "" ``` 该库已发布到maven中央仓库,请使用最新版本。仅将本库导入构建系统(例如gradle、sbt)是不够的。你需要多走一步。 @@ -142,4 +112,4 @@ Thanks to JetBrains for providing me with a free license, which is a strong supp [Link-Jetbrains]: https://plugins.jetbrains.com/plugin/17202-scala-macro-tools [Link-Codecov]: https://codecov.io/gh/bitlap/smt [Link-Scaladex]: https://index.scala-lang.org/bitlap/smt/smt-annotations -[Link-Snapshots]: https://s01.oss.sonatype.org/content/repositories/snapshots/org/bitlap/ +[Link-Snapshots]: https://s01.oss.sonatype.org/content/repositories/snapshots/org/bitlap/ \ No newline at end of file diff --git a/build.sbt b/build.sbt index d0639a72..0053c275 100644 --- a/build.sbt +++ b/build.sbt @@ -11,15 +11,8 @@ ThisBuild / resolvers ++= Seq( lazy val scala212 = "2.12.14" lazy val scala211 = "2.11.12" lazy val scala213 = "2.13.8" -lazy val lastVersionForExamples = "0.7.3" -lazy val configVersion = "1.4.2" lazy val scalatestVersion = "3.2.13" -lazy val zioVersion = "1.0.16" -lazy val zioLoggingVersion = "0.5.14" -lazy val caffeineVersion = "2.9.3" -lazy val zioRedisVersion = "0.0.0+381-86c20614-SNAPSHOT" // 实验性质的 -lazy val zioSchemaVersion = "0.1.9" lazy val scalaLoggingVersion = "3.9.5" lazy val log4jVersion = "2.18.0" lazy val scalaCollectionCompatVersion = "2.8.1" @@ -49,54 +42,6 @@ lazy val commonSettings = publishLocalConfiguration := publishLocalConfiguration.value.withOverwrite(true) ) -lazy val `smt-cacheable` = (project in file("smt-cacheable")) - .settings(commonSettings) - .settings(Publishing.publishSettings) - .settings( - name := "smt-cacheable", - crossScalaVersions := List(scala213, scala212), - libraryDependencies ++= Seq( - "dev.zio" %% "zio" % zioVersion % Provided, - "dev.zio" %% "zio-streams" % zioVersion, - "dev.zio" %% "zio-logging" % zioLoggingVersion - ) - ) - .settings(paradise()) - .enablePlugins(HeaderPlugin) - -lazy val `smt-cacheable-caffeine` = (project in file("smt-cacheable-caffeine")) - .settings(commonSettings) - .settings(Publishing.publishSettings) - .settings( - name := "smt-cacheable-caffeine", - crossScalaVersions := List(scala213, scala212), - libraryDependencies ++= Seq( - "com.typesafe" % "config" % configVersion, - "com.github.ben-manes.caffeine" % "caffeine" % caffeineVersion - ) - ) - .dependsOn(`smt-cacheable` % "compile->compile;test->test") - .settings(paradise()) - .enablePlugins(HeaderPlugin) - -lazy val `smt-cacheable-redis` = (project in file("smt-cacheable-redis")) - .settings(commonSettings) - .settings(Publishing.publishSettings) - .settings( - name := "smt-cacheable-redis", - crossScalaVersions := List(scala213, scala212), - libraryDependencies ++= Seq( - "dev.zio" %% "zio-redis" % zioRedisVersion % Provided, - "com.typesafe" % "config" % configVersion, - "dev.zio" %% "zio-schema" % zioSchemaVersion, - "dev.zio" %% "zio-schema-json" % zioSchemaVersion, - "dev.zio" %% "zio-schema-derivation" % zioSchemaVersion % Test - ) - ) - .dependsOn(`smt-cacheable` % "compile->compile;test->test") - .settings(paradise()) - .enablePlugins(HeaderPlugin) - lazy val `smt-csv` = (project in file("smt-csv")) .settings(commonSettings) .settings( @@ -160,16 +105,10 @@ lazy val `smt-annotations` = (project in file("smt-annotations")) lazy val `smt` = (project in file(".")) .aggregate( `smt-annotations`, - `smt-cacheable`, - `smt-cacheable-redis`, - `smt-cacheable-caffeine`, `smt-csv`, `smt-csv-derive`, `smt-cache`, - `smt-common`, - `scala2-11`, - `scala2-12`, - `scala2-13` + `smt-common` ) .settings( commands ++= Commands.value, @@ -196,54 +135,6 @@ lazy val `smt` = (project in file(".")) ) ) -lazy val `scala2-13` = (project in file("examples/scala2-13")) - .settings(scalaVersion := scala213) - .settings( - libraryDependencies ++= Seq( - "org.bitlap" %% "smt-annotations" % lastVersionForExamples, - "org.bitlap" %% "smt-cacheable" % lastVersionForExamples, - "org.bitlap" %% "smt-cacheable-redis" % lastVersionForExamples, - "org.bitlap" %% "smt-cacheable-caffeine" % lastVersionForExamples, - "dev.zio" %% "zio-redis" % zioRedisVersion, - "dev.zio" %% "zio" % zioVersion - ) - ) - .settings( - publish / skip := true, - Compile / scalacOptions ++= List("-Ymacro-annotations", "-Ywarn-unused") - ) - -lazy val `scala2-12` = (project in file("examples/scala2-12")) - .settings(scalaVersion := scala212) - .settings( - libraryDependencies ++= Seq( - "org.bitlap" %% "smt-annotations" % lastVersionForExamples, - "org.bitlap" %% "smt-cacheable" % lastVersionForExamples, - "org.bitlap" %% "smt-cacheable-redis" % lastVersionForExamples, - "org.bitlap" %% "smt-cacheable-caffeine" % lastVersionForExamples, - "dev.zio" %% "zio-redis" % zioRedisVersion, - "dev.zio" %% "zio" % zioVersion - ) - ) - .settings( - publish / skip := true, - scalacOptions ++= List("-Xlint:unused"), - paradise() - ) - -lazy val `scala2-11` = (project in file("examples/scala2-11")) - .settings(scalaVersion := scala211) - .settings( - libraryDependencies ++= Seq( - "org.bitlap" %% "smt-annotations" % lastVersionForExamples - ) - ) - .settings( - publish / skip := true, - scalacOptions ++= List("-Xlint:unused"), - paradise() - ) - def paradise(): Def.Setting[Seq[ModuleID]] = libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, n)) if n < 13 => Some("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) diff --git a/examples/scala2-11/src/main/scala/org/bitlap/tools/Main.scala b/examples/scala2-11/src/main/scala/org/bitlap/tools/Main.scala deleted file mode 100644 index 1dc064f8..00000000 --- a/examples/scala2-11/src/main/scala/org/bitlap/tools/Main.scala +++ /dev/null @@ -1,20 +0,0 @@ -package org.bitlap.tools - -/** @author - * 梦境迷离 - * @since 2021/6/16 - * @version 1.0 - */ -object Main extends App { - - @toString(includeInternalFields = true, includeFieldNames = true) - class TestClass(val i: Int = 0, var j: Int) { - val y: Int = 0 - var z: String = "hello" - var x: String = "world" - } - - val s = new TestClass(1, 2).toString - println(s) - -} diff --git a/examples/scala2-12/src/main/scala/org/bitlap/tools/CacheExample.scala b/examples/scala2-12/src/main/scala/org/bitlap/tools/CacheExample.scala deleted file mode 100644 index a1dbbaf9..00000000 --- a/examples/scala2-12/src/main/scala/org/bitlap/tools/CacheExample.scala +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.tools - -import org.bitlap.cacheable.core.{ cacheable, Cache, Utils } -import org.bitlap.cacheable.redis.Implicits._ -import zio.{ ExitCode, UIO, URIO, ZIO } -import zio.console.putStrLn -import zio.stream.ZStream - -import scala.util.Random - -/** use these function to test it. - * - * @author - * 梦境迷离 - * @version 1.0,2022/3/18 - */ -object CacheExample extends zio.App { - - // import org.bitlap.cacheable.redis.Implicits._ - def readAliasStreamFunction(id: Int, key: String): zio.stream.Stream[Throwable, String] = { - val $result = ZStream.fromEffect(ZIO.effect("hello world" + Random.nextInt())) - Cache($result)(List("UseCaseExample", "readAliasStreamFunction"), List(id, key)) - } - - def readStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = { - val $result = ZStream.fromEffect(ZIO.effect("hello world" + Random.nextInt())) - Cache($result)(List("UseCaseExample", "readStreamFunction"), List(id, key)) - } - - def updateStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = { - val $result = ZStream.fromEffect(ZIO.effect("hello world" + Random.nextInt())) - Cache.evict($result)(List("readFunction1", "readFunction2")) // not macro, not check whether read function is exists - } - - @cacheable // caffeine - def readStreamEntityFunction(id: Int, key: String): ZStream[Any, Throwable, CacheValue] = - ZStream.fromEffect(ZIO.effect(CacheValue(Random.nextInt() + ""))) - - override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = - (for { - cache1 <- readStreamEntityFunction(1, "hello-world").runHead - cache2 <- updateStreamFunction(2, "helloworld").runHead - _ <- Utils.debug(s"${cache1.toString} ${cache2.toString}") - _ <- putStrLn("Hello good to meet you!") - } yield ()).foldM( - e => Utils.debug(s"error => $e").exitCode, - _ => UIO.effectTotal(ExitCode.success) - ) - -} diff --git a/examples/scala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala b/examples/scala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala deleted file mode 100644 index 4ea94e1e..00000000 --- a/examples/scala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala +++ /dev/null @@ -1,13 +0,0 @@ -package org.bitlap.tools -import zio.schema.{ DeriveSchema, Schema } - -/** @author - * 梦境迷离 - * @version 1.0,2022/3/22 - */ -case class CacheValue(i: String) - -object CacheValue { - - implicit val cacheValueSchema: Schema[CacheValue] = DeriveSchema.gen[CacheValue] -} diff --git a/examples/scala2-12/src/main/scala/org/bitlap/tools/Main.scala b/examples/scala2-12/src/main/scala/org/bitlap/tools/Main.scala deleted file mode 100644 index 1dc064f8..00000000 --- a/examples/scala2-12/src/main/scala/org/bitlap/tools/Main.scala +++ /dev/null @@ -1,20 +0,0 @@ -package org.bitlap.tools - -/** @author - * 梦境迷离 - * @since 2021/6/16 - * @version 1.0 - */ -object Main extends App { - - @toString(includeInternalFields = true, includeFieldNames = true) - class TestClass(val i: Int = 0, var j: Int) { - val y: Int = 0 - var z: String = "hello" - var x: String = "world" - } - - val s = new TestClass(1, 2).toString - println(s) - -} diff --git a/examples/scala2-13/src/main/scala/org/bitlap/tools/CacheExample.scala b/examples/scala2-13/src/main/scala/org/bitlap/tools/CacheExample.scala deleted file mode 100644 index 37a3ca67..00000000 --- a/examples/scala2-13/src/main/scala/org/bitlap/tools/CacheExample.scala +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.tools - -import scala.util.Random -import org.bitlap.cacheable.core.{ Cache, Utils } -import org.bitlap.cacheable.caffeine.Implicits._ -import zio.console.putStrLn -import zio.stream.ZStream -import zio.{ ExitCode, UIO, URIO, ZIO } -import org.bitlap.cacheable.core.cacheable - -/** use these function to test it. - * - * @author - * 梦境迷离 - * @version 1.0,2022/3/18 - */ -object CacheExample extends zio.App { - - // import org.bitlap.cacheable.caffeine.Implicits._ - def readAliasStreamFunction(id: Int, key: String): zio.stream.Stream[Throwable, String] = { - val $result = ZStream.fromEffect(ZIO.effect("hello world" + Random.nextInt())) - Cache($result)(List("UseCaseExample", "readAliasStreamFunction"), List(id, key)) - } - - def readStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = { - val $result = ZStream.fromEffect(ZIO.effect("hello world" + Random.nextInt())) - Cache($result)(List("UseCaseExample", "readStreamFunction"), List(id, key)) - } - - def updateStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = { - val $result = ZStream.fromEffect(ZIO.effect("hello world" + Random.nextInt())) - Cache.evict($result)(List("readFunction1", "readFunction2")) // not macro, not check whether read function is exists - } - - @cacheable // caffeine - def readStreamEntityFunction(id: Int, key: String): ZStream[Any, Throwable, CacheValue] = - ZStream.fromEffect(ZIO.effect(CacheValue(Random.nextInt() + ""))) - - override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = - (for { - cache1 <- readStreamEntityFunction(1, "hello-world").runHead - cache2 <- updateStreamFunction(2, "helloworld").runHead - _ <- Utils.debug(s"${cache1.toString} ${cache2.toString}") - _ <- putStrLn("Hello good to meet you!") - } yield ()).foldM( - e => Utils.debug(s"error => $e").exitCode, - _ => UIO.effectTotal(ExitCode.success) - ) - -} diff --git a/examples/scala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala b/examples/scala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala deleted file mode 100644 index 58b6b091..00000000 --- a/examples/scala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala +++ /dev/null @@ -1,16 +0,0 @@ -package org.bitlap.tools - -import zio.schema.{ DeriveSchema, Schema } - -/** @author - * 梦境迷离 - * @version 1.0,2022/3/22 - */ - -// The case class should be here, not in the test -case class CacheValue(i: String) - -object CacheValue { - - implicit val cacheValueSchema: Schema[CacheValue] = DeriveSchema.gen[CacheValue] -} diff --git a/examples/scala2-13/src/main/scala/org/bitlap/tools/Main.scala b/examples/scala2-13/src/main/scala/org/bitlap/tools/Main.scala deleted file mode 100644 index 1f3bf788..00000000 --- a/examples/scala2-13/src/main/scala/org/bitlap/tools/Main.scala +++ /dev/null @@ -1,33 +0,0 @@ -package org.bitlap.tools - -/** @author - * 梦境迷离 - * @since 2021/6/16 - * @version 1.0 - */ -object Main extends App { - - @toString(includeInternalFields = true, includeFieldNames = true) - class TestClass(val i: Int = 0, var j: Int) { - val y: Int = 0 - var z: String = "hello" - var x: String = "world" - } - - val s = new TestClass(1, 2).toString - println(s) - - @toString(includeInternalFields = false, includeFieldNames = true) - @apply - @builder class A2(int: Int, val j: Int, var k: Option[String] = None, t: Option[Long] = Some(1L)) { - private val a: Int = 1 - var b: Int = 1 - protected var c: Int = _ - - def helloWorld: String = "hello world" - } - - println(A2(1, 2, None, None)) // use apply and toString - println(A2.builder().int(1).j(2).k(Option("hello")).t(None).build()) // use builder and toString - -} diff --git a/project/plugins.sbt b/project/plugins.sbt index 9384c5e2..b281af2e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,6 +3,5 @@ addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.7.0") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3") -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1") diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/LogLevel.scala b/smt-annotations/src/main/scala/org/bitlap/tools/LogLevel.scala index 840063df..45ba8643 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/LogLevel.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/LogLevel.scala @@ -35,11 +35,11 @@ object LogLevel extends Enumeration { private[bitlap] def getLogLevel(shortType: String): LogLevel = { // TODO not good way - val tpe1 = s"$PACKAGE.elapsed.$shortType" // LogLevel.INFO - val tpe2 = s"$PACKAGE.elapsed.LogLevel.$shortType" // INFO + val tpe1 = s"$PACKAGE.$shortType" // LogLevel.INFO + val tpe2 = s"$PACKAGE.LogLevel.$shortType" // INFO val v = LogLevel.values.find { p => - s"$PACKAGE.elapsed.LogLevel.${p.toString}" == tpe1 || - s"$PACKAGE.elapsed.LogLevel.${p.toString}" == tpe2 || s"$PACKAGE.elapsed.LogLevel.${p.toString}" == shortType + s"$PACKAGE.LogLevel.${p.toString}" == tpe1 || + s"$PACKAGE.LogLevel.${p.toString}" == tpe2 || s"$PACKAGE.LogLevel.${p.toString}" == shortType }.get.toString LogLevel.withName(v) } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/apply.scala b/smt-annotations/src/main/scala/org/bitlap/tools/apply.scala index c7ab3a7e..44481380 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/apply.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/apply.scala @@ -21,7 +21,7 @@ package org.bitlap.tools -import org.bitlap.tools.macros.applyMacro +import org.bitlap.tools.internal.applyMacro import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/builder.scala b/smt-annotations/src/main/scala/org/bitlap/tools/builder.scala index 9d051fd3..139247c2 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/builder.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/builder.scala @@ -21,7 +21,7 @@ package org.bitlap.tools -import org.bitlap.tools.macros.builderMacro +import org.bitlap.tools.internal.builderMacro import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/constructor.scala b/smt-annotations/src/main/scala/org/bitlap/tools/constructor.scala index 2c51b5e4..f6ae83e2 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/constructor.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/constructor.scala @@ -21,7 +21,7 @@ package org.bitlap.tools -import org.bitlap.tools.macros.constructorMacro +import org.bitlap.tools.internal.constructorMacro import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/elapsed.scala b/smt-annotations/src/main/scala/org/bitlap/tools/elapsed.scala index 09732380..3952cd31 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/elapsed.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/elapsed.scala @@ -22,7 +22,7 @@ package org.bitlap.tools import org.bitlap.tools.LogLevel.LogLevel -import org.bitlap.tools.macros.elapsedMacro.ElapsedProcessor +import org.bitlap.tools.internal.elapsedMacro.ElapsedProcessor import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/equalsAndHashCode.scala b/smt-annotations/src/main/scala/org/bitlap/tools/equalsAndHashCode.scala index ca5f96cf..76502ed4 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/equalsAndHashCode.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/equalsAndHashCode.scala @@ -21,7 +21,7 @@ package org.bitlap.tools -import org.bitlap.tools.macros.equalsAndHashCodeMacro.EqualsAndHashCodeProcessor +import org.bitlap.tools.internal.equalsAndHashCodeMacro.EqualsAndHashCodeProcessor import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/AbstractMacroProcessor.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/AbstractMacroProcessor.scala similarity index 97% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/AbstractMacroProcessor.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/AbstractMacroProcessor.scala index 750ccc0c..fff8819f 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/AbstractMacroProcessor.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/AbstractMacroProcessor.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import java.time.ZonedDateTime import java.time.format.DateTimeFormatter @@ -300,7 +300,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { def existsSuperClassExcludeSdkClass(superClasses: Seq[Tree]): Boolean = superClasses.nonEmpty && !superClasses.forall(sc => SDKClasses.contains(sc.toString())) - private[macros] final case class ValDefAccessor( + private[internal] final case class ValDefAccessor( mods: Modifiers, name: TermName, tpt: Tree, @@ -328,12 +328,12 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { } /** Retrieves the accessor fields on a class and returns a Seq of - * [[org.bitlap.tools.macros.AbstractMacroProcessor#ValDefAccessor]]. + * [[org.bitlap.tools.internal.AbstractMacroProcessor#ValDefAccessor]]. * * @param params * The list of params retrieved from the class * @return - * Return a sequence of [[org.bitlap.tools.macros.AbstractMacroProcessor#ValDefAccessor]] + * Return a sequence of [[org.bitlap.tools.internal.AbstractMacroProcessor#ValDefAccessor]] */ def valDefAccessors(params: Seq[Tree]): Seq[ValDefAccessor] = params.map { case ValDef(mods, name: TermName, tpt: Tree, rhs) => @@ -345,7 +345,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * @param classDecl * @return * Return the expansion of the class definition as - * [[org.bitlap.tools.macros.AbstractMacroProcessor#ClassDefinition]] + * [[org.bitlap.tools.internal.AbstractMacroProcessor#ClassDefinition]] */ def mapToClassDeclInfo(classDecl: ClassDef): ClassDefinition = { val q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }" = @@ -368,7 +368,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { * @param moduleDef * @return * Return the expansion of the class definition as - * [[org.bitlap.tools.macros.AbstractMacroProcessor#ClassDefinition]] + * [[org.bitlap.tools.internal.AbstractMacroProcessor#ClassDefinition]] */ def mapToModuleDeclInfo(moduleDef: ModuleDef): ClassDefinition = { val q"$mods object $tpname extends { ..$earlydefns } with ..$parents { $self => ..$stats }" = moduleDef @@ -439,7 +439,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) { DefDef(mods, name, tparams, vparamss, tpt, defBodyAction) } - private[macros] case class ClassDefinition( + private[internal] case class ClassDefinition( self: ValDef, mods: Modifiers, className: TypeName, diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/applyMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/applyMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/applyMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/applyMacro.scala index 8ee940a2..c5267f9a 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/applyMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/applyMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import scala.reflect.macros.whitebox diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/builderMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/builderMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/builderMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/builderMacro.scala index 607cc78d..6fc28ccc 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/builderMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/builderMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import scala.reflect.macros.whitebox diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/constructorMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/constructorMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/constructorMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/constructorMacro.scala index fb4e7239..216ee863 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/constructorMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/constructorMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import scala.reflect.macros.whitebox diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/elapsedMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/elapsedMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/elapsedMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/elapsedMacro.scala index cd5b1873..af16fe04 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/elapsedMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/elapsedMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import org.bitlap.tools.LogLevel.LogLevel import org.bitlap.tools.{ LogLevel, PACKAGE } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/equalsAndHashCodeMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/equalsAndHashCodeMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/equalsAndHashCodeMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/equalsAndHashCodeMacro.scala index 65bb252e..a8253098 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/equalsAndHashCodeMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/equalsAndHashCodeMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import scala.reflect.macros.whitebox diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/javaCompatibleMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/javaCompatibleMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/javaCompatibleMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/javaCompatibleMacro.scala index 57a3a31a..f7d05bdb 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/javaCompatibleMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/javaCompatibleMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import scala.reflect.macros.whitebox diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/logMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/logMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/logMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/logMacro.scala index 2f85a3da..634acb43 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/logMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/logMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import org.bitlap.tools.logs.LogType._ import org.bitlap.tools.logs.{ LogArgument, LogType } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/macros.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/macros.scala similarity index 95% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/macros.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/macros.scala index f7e66725..416c3fa3 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/macros.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/macros.scala @@ -26,9 +26,9 @@ package org.bitlap.tools * @since 2021/7/7 * @version 1.0 */ -package object macros { +package object internal { - private[macros] object ErrorMessage { + private[internal] object ErrorMessage { // common error msg final lazy val ONLY_CLASS: String = "Annotation is only supported on class." final lazy val ONLY_CASE_CLASS: String = "Annotation is only supported on case class." diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/macros/toStringMacro.scala b/smt-annotations/src/main/scala/org/bitlap/tools/internal/toStringMacro.scala similarity index 99% rename from smt-annotations/src/main/scala/org/bitlap/tools/macros/toStringMacro.scala rename to smt-annotations/src/main/scala/org/bitlap/tools/internal/toStringMacro.scala index fc89fb84..a73fb4ac 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/macros/toStringMacro.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/internal/toStringMacro.scala @@ -19,7 +19,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.bitlap.tools.macros +package org.bitlap.tools.internal import scala.reflect.macros.whitebox diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/javaCompatible.scala b/smt-annotations/src/main/scala/org/bitlap/tools/javaCompatible.scala index 4efc93a1..92caabd4 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/javaCompatible.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/javaCompatible.scala @@ -22,7 +22,7 @@ package org.bitlap.tools import scala.annotation.{ compileTimeOnly, StaticAnnotation } -import org.bitlap.tools.macros.javaCompatibleMacro +import org.bitlap.tools.internal.javaCompatibleMacro /** annotation to generate non-parameter constructor and get/set method for case classes. Fields marked `private[this]` * in curry are not supported ! diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/log.scala b/smt-annotations/src/main/scala/org/bitlap/tools/log.scala index b395d288..acbf4506 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/log.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/log.scala @@ -22,7 +22,7 @@ package org.bitlap.tools import org.bitlap.tools.logs.LogType -import org.bitlap.tools.macros.logMacro +import org.bitlap.tools.internal.logMacro import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/logs/LogType.scala b/smt-annotations/src/main/scala/org/bitlap/tools/logs/LogType.scala index 1a04149c..ec9144ec 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/logs/LogType.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/logs/LogType.scala @@ -45,7 +45,7 @@ object LogType extends Enumeration { def getLogImpl(logType: LogType): BaseLog = types.getOrElse(logType, default = throw new Exception(s"Not support log type: $logType")) - // TODO not use Enumeratio + // TODO not use Enumeration def getLogType(shortType: String): LogType = { val tpe1 = s"$PACKAGE.logs.$shortType" // LogType.JLog val tpe2 = s"$PACKAGE.logs.LogType.$shortType" // JLog diff --git a/smt-annotations/src/main/scala/org/bitlap/tools/toString.scala b/smt-annotations/src/main/scala/org/bitlap/tools/toString.scala index de026613..668f73c7 100644 --- a/smt-annotations/src/main/scala/org/bitlap/tools/toString.scala +++ b/smt-annotations/src/main/scala/org/bitlap/tools/toString.scala @@ -21,7 +21,7 @@ package org.bitlap.tools -import org.bitlap.tools.macros.toStringMacro +import org.bitlap.tools.internal.toStringMacro import scala.annotation.{ compileTimeOnly, StaticAnnotation } diff --git a/smt-cacheable-caffeine/src/main/resources/reference.conf b/smt-cacheable-caffeine/src/main/resources/reference.conf deleted file mode 100644 index c817a0a9..00000000 --- a/smt-cacheable-caffeine/src/main/resources/reference.conf +++ /dev/null @@ -1,6 +0,0 @@ -caffeine { - maximumSize = 100 - expireAfterWriteSeconds = 60 - disabledLog = true - calculateResultTimeout = "5 s" -} \ No newline at end of file diff --git a/smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/Implicits.scala b/smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/Implicits.scala deleted file mode 100644 index fdef2917..00000000 --- a/smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/Implicits.scala +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.caffeine - -import zio.Chunk -import zio.Task - -import scala.concurrent.Await -import org.bitlap.cacheable.core._ -import zio.ZIO -import zio.stream.ZStream - -/** redis cache - * - * @author - * 梦境迷离 - * @version 1.0,2022/3/21 - */ -object Implicits { - - implicit def StreamUpdateCache[T]: ZStreamUpdateCache[T] = new ZStreamUpdateCache[T] { - override def evict(business: => UZStream[T])(identities: List[String]): UZStream[T] = - for { - updateResult <- ZStream - .fromIterable(identities) - .flatMap(key => ZStream.fromEffect(ZCaffeine.del(key))) *> business tap (ur => - Utils - .debug(s"Caffeine ZStream update: identities:[$identities], updateResult:[$ur]") - .unless(ZCaffeine.disabledLog) - ) - } yield updateResult - } - - implicit def StreamReadCache[T]: ZStreamCache[T] = new ZStreamCache[T] { - override def getIfPresent( - business: => UZStream[T] - )(identities: List[String], args: List[_]): UZStream[T] = { - val key = cacheKey(identities) - val field = cacheField(args) - val syncResultFuture = zio.Runtime.global.unsafeRunToFuture(business.runCollect) - lazy val result = Await.result(syncResultFuture, ZCaffeine.calculateResultTimeout) - for { - chunk <- ZStream.fromEffect( - ZCaffeine - .hGet[Chunk[T]](key, field) - .map(_.getOrElse(Chunk.empty)) - .tap(cv => - Utils - .debug(s"Caffeine ZStream getIfPresent: identity:[$key],field:[$field],cacheValue:[$cv]") - .unless(ZCaffeine.disabledLog) - ) - ) - ret <- ZStream - .fromEffect(if (chunk.isEmpty) ZCaffeine.hSet(key, field, result).as(result) else ZIO.succeed(chunk)) - .tap(result => - Utils - .debug(s"Caffeine ZStream getIfPresent: identity:[$key],field:[$field],result:[$result]") - .unless(ZCaffeine.disabledLog) - ) - r <- ZStream.fromIterable(ret) - } yield r - } - } - - implicit def UpdateCache[T]: ZIOUpdateCache[T] = new ZIOUpdateCache[T] { - override def evict(business: => Task[T])(identities: List[String]): Task[T] = - for { - updateResult <- ZIO.foreach_(identities)(key => ZCaffeine.del(key)) *> business tap (updateResult => - Utils - .debug(s"Caffeine ZIO update: identities:[$identities], updateResult:[$updateResult]") - .unless(ZCaffeine.disabledLog) - ) - } yield updateResult - } - - implicit def ReadCache[T]: ZIOCache[T] = new ZIOCache[T] { - override def getIfPresent( - business: => Task[T] - )(identities: List[String], args: List[_]): Task[T] = { - val key = cacheKey(identities) - val field = cacheField(args) - for { - cacheValue <- ZCaffeine.hGet[T](key, field) - _ <- Utils - .debug(s"Caffeine ZIO getIfPresent: identity:[$key], field:[$field], cacheValue:[$cacheValue]") - .unless(ZCaffeine.disabledLog) - result <- cacheValue - .fold(business.tap(r => ZCaffeine.hSet(key, field, r).as(r)))(value => ZIO.effectTotal(value)) - .tap(result => - Utils - .debug(s"Caffeine ZIO getIfPresent: identity:[$key], field:[$field], result:[$result]") - .unless(ZCaffeine.disabledLog) - ) - } yield result - } - } -} diff --git a/smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/ZCaffeine.scala b/smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/ZCaffeine.scala deleted file mode 100644 index 10707618..00000000 --- a/smt-cacheable-caffeine/src/main/scala/org/bitlap/cacheable/caffeine/ZCaffeine.scala +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.caffeine - -import com.github.benmanes.caffeine.cache.{ Cache, Caffeine } -import com.typesafe.config.{ Config, ConfigFactory } -import org.bitlap.cacheable.core.Utils - -import java.util.concurrent.{ ConcurrentHashMap, TimeUnit } -import scala.concurrent.duration.Duration -import zio.Task - -/** @author - * 梦境迷离 - * @version 1.0,2022/3/21 - */ -object ZCaffeine { - - private val conf: Config = ConfigFactory.load("reference.conf") - private val custom: Config = ConfigFactory.load("application.conf").withFallback(conf) - - private[caffeine] lazy val disabledLog: Boolean = custom.getBoolean("caffeine.disabledLog") - private[caffeine] lazy val calculateResultTimeout: Duration = Duration( - custom.getString("caffeine.calculateResultTimeout") - ) - - private lazy val maximumSize: Int = custom.getInt("caffeine.maximumSize") - private lazy val expireAfterWriteSeconds: Int = custom.getInt("caffeine.expireAfterWriteSeconds") - - val hashCache: Cache[String, ConcurrentHashMap[String, Any]] = Caffeine - .newBuilder() - .maximumSize(maximumSize) - .expireAfterWrite(expireAfterWriteSeconds, TimeUnit.SECONDS) - .build[String, ConcurrentHashMap[String, Any]] - - def hGet[T](key: String, field: String): Task[Option[T]] = - Utils.effectBlocking { - key.synchronized { - val hashMap = hashCache.getIfPresent(key) - if (hashMap == null || hashMap.isEmpty) { - None - } else { - val fieldValue = hashMap.get(field) - if (fieldValue == null || !fieldValue.isInstanceOf[T]) { - None - } else { - Some(fieldValue.asInstanceOf[T]) - } - } - } - } - - def hDel(key: String, field: String): Task[Unit] = - Utils.effectBlocking { - key.synchronized { - val hashMap = hashCache.getIfPresent(key) - if (hashMap == null || hashMap.isEmpty) { - () - } else { - hashMap.remove(field) - hashCache.put(key, new ConcurrentHashMap(hashMap)) - } - } - } - - def del(key: String): Task[Unit] = - Utils.effectBlocking { - key.synchronized { - hashCache.invalidate(key) - } - } - - def hSet(key: String, field: String, value: Any): Task[Unit] = - Utils.effectBlocking { - key.synchronized { - val hashMap = hashCache.getIfPresent(key) - if (hashMap == null || hashMap.isEmpty) { - val chm = new ConcurrentHashMap[String, Any]() - chm.put(field, value) - hashCache.put(key, chm) - } else { - hashMap.put(field, value) - hashCache.put(key, new ConcurrentHashMap(hashMap)) - } - } - } -} diff --git a/smt-cacheable-caffeine/src/test/resources/application.conf b/smt-cacheable-caffeine/src/test/resources/application.conf deleted file mode 100644 index 31760642..00000000 --- a/smt-cacheable-caffeine/src/test/resources/application.conf +++ /dev/null @@ -1,5 +0,0 @@ -caffeine { - maximumSize = 100 - expireAfterWriteSeconds = 60 - disabledLog = false -} \ No newline at end of file diff --git a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheEvictTest.scala b/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheEvictTest.scala deleted file mode 100644 index eaaa3759..00000000 --- a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheEvictTest.scala +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.caffeine - -import org.bitlap.cacheable.core.{ cacheEvict, cacheable } -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import zio.ZIO -import zio.stream.ZStream - -import scala.util.Random - -/** @author - * 梦境迷离 - * @since 2022/3/19 - * @version 1.0 - */ -class CacheEvictTest extends AnyFlatSpec with Matchers { - - val runtime = zio.Runtime.default - - // write readStreamFunction1 method , otherwise: The specified method: `readStreamFunction1` does not exist in enclosing class: `CacheEvictTest`! - def readStreamFunction1: String = "hello world" - - def readStreamFunction: String = "hello world" - - def readIOFunction: String = "hello world" - - val readIOMethodName = "readIOFunction" - val readStreamMethodName = "readStreamFunction" - - "cacheEvict1" should "expected annotation pattern" in { - @cacheEvict(true, List()) - def updateFunction3(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - - @cacheEvict(local = true) - def updateFunction4(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - - @cacheEvict(values = List()) - def updateFunction5(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - - @cacheEvict() - def updateFunction6(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - } - - "cacheEvict2" should "unexpected annotation pattern" in { - """ - | @cacheEvict(values = List("readStreamFunction1"), local = true) - | def updateFunction1(id: Int, key: String): ZIO[Any, Throwable, String] = { - | ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - | } - |""".stripMargin shouldNot compile - } - - "cacheEvict3" should "ok when return type is case class" in { - @cacheEvict(local = true) - def updateEntityFunction(id: Int, key: String): ZIO[Any, Throwable, CacheValue] = - ZIO.effect(CacheValue(Random.nextInt() + "")) - } - - "cacheEvict4" should "zio operation is ok with redis" in { - val cacheValue = Random.nextInt().toString - - @cacheable(local = true) - def readIOFunction(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(cacheValue) - - @cacheEvict(local = true, values = List("readIOFunction")) - def updateIOFunction(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(Random.nextInt() + "") - - val result = runtime.unsafeRun(for { - _ <- ZCaffeine.del("CacheableTest-" + readIOMethodName) - read <- readIOFunction(1, "hello") - update <- updateIOFunction(1, "hello") - cache <- ZCaffeine.hGet[String]("CacheableTest-" + readIOMethodName, "1-hello") - } yield cache) - result shouldEqual None - } - - "cacheEvict5" should "zstream operation is ok with redis" in { - val cacheValue = Random.nextInt().toString - - @cacheable(local = true) - def readStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = - ZStream.fromEffect(ZIO.effect(cacheValue)) - - @cacheEvict(local = true, values = List("readStreamFunction")) - def updateStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = - ZStream.fromEffect(ZIO.effect(Random.nextInt() + "")) - - val result = runtime.unsafeRun(for { - _ <- ZCaffeine.del("CacheableTest-" + readStreamMethodName) - read <- readStreamFunction(1, "hello").runHead - update <- updateStreamFunction(1, "hello").runHead - cache <- ZCaffeine.hGet[String]("CacheableTest-" + readStreamMethodName, "1-hello") - } yield cache) - result shouldEqual None - } -} diff --git a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheValue.scala b/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheValue.scala deleted file mode 100644 index 1e1f2e4b..00000000 --- a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheValue.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.caffeine - -case class CacheValue(i: String) diff --git a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheableTest.scala b/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheableTest.scala deleted file mode 100644 index 4832acaf..00000000 --- a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CacheableTest.scala +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.caffeine - -import org.bitlap.cacheable.core.{ cacheEvict, cacheable } -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import zio.stream.ZStream -import zio.{ Chunk, Task, ZIO } - -import java.util -import scala.util.Random - -/** @author - * 梦境迷离 - * @since 2021/8/7 - * @version 1.0 - */ -class CacheableTest extends AnyFlatSpec with Matchers { - - val runtime = zio.Runtime.default - - def readIOFunction(id: Int, key: String) = ??? - - "cacheable1" should "ok" in { - @cacheable(local = true) - def readAliasStreamFunction2(id: Int, key: String): zio.stream.Stream[Throwable, String] = - ZStream.fromEffect(ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}")) - } - - "cacheable2" should "ok" in { - @cacheable(local = true) - def readFunction(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - } - - "cacheable3" should "String cannot compile" in { - """ - | @cacheable(local = true) - | def readFunction(id: Int, key: String): String = { - | s"hello world--$id-$key-${Random.nextInt()}" - | } - |""".stripMargin shouldNot compile - } - - "cacheable4" should "need specified type, otherwise cannot compile" in { - """ - | @cacheable(local = true) - | def readFunction(id: Int, key: String) = { - | s"hello world--$id-$key-${Random.nextInt()}" - | } - |""".stripMargin shouldNot compile - } - - "cacheable5" should "expected annotation pattern" in { - @cacheable(local = true) - def readFunction1(id: Int, key: String): Task[String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - - @cacheable() - def readFunction3(id: Int, key: String): Task[String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - } - - "cacheable6" should "zio operation is ok with redis" in { - val cacheValue = Random.nextInt().toString - - @cacheable(true) - def readIOFunction(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(cacheValue) - - val result = runtime.unsafeRun(for { - _ <- ZCaffeine.del("CacheableTest-readIOFunction") - method <- readIOFunction(1, "hello") - cache <- ZCaffeine.hGet[String]("CacheableTest-readIOFunction", "1-hello") - } yield method -> cache) - Some(result._1) shouldEqual result._2 - } - - // =================================================================================================================== - // test multi-threads - - case class StoreData(id: String, name: String) - - val globalId = Random.nextInt().toString - val storeMap = new util.HashMap[String, StoreData]() - storeMap.put(globalId + "", StoreData(globalId, "zhangsan")) - - "cacheable7" should "test multi-threads" in { - @cacheable(true) - def readIOFunction(id: Int): ZStream[Any, Throwable, StoreData] = - ZStream.fromEffect( - ZIO.effect(storeMap.get(id + "")) - ) - - @cacheEvict(local = true) - def updateIOFunction(value: String): ZStream[Any, Throwable, StoreData] = - ZStream.fromEffect( - ZIO.effect(storeMap.put(globalId, StoreData(globalId, value))) - ) - - val result = runtime.unsafeRun(for { - _ <- ZCaffeine.del("CacheableTest-readIOFunction") - method <- readIOFunction(globalId.toInt).runHead - update <- updateIOFunction("lisi").runHead - after <- readIOFunction(globalId.toInt).runHead - } yield Some("lisi") -> after.map(_.name)) - result._1 shouldEqual result._2 - } - - "cacheable8" should "test multi-threads" in { - @cacheable(true) - def readIOFunction(id: Int): ZStream[Any, Throwable, StoreData] = - ZStream.fromEffect( - ZIO.effect(storeMap.get(id + "")) - ) - - @cacheEvict(local = true) - def updateIOFunction(id: String): ZStream[Any, Throwable, StoreData] = - ZStream.fromEffect( - ZIO.effect(storeMap.put(globalId, StoreData(id, "zhangsan"))) - ) - - val newId = Random.nextInt().toString - val result = runtime.unsafeRun(for { - _ <- ZCaffeine.del("CacheableTest-readIOFunction") - method <- readIOFunction(globalId.toInt).runHead - update <- updateIOFunction(newId).runHead - after <- readIOFunction(globalId.toInt).runHead - } yield Some(newId) -> after.map(_.id)) - result._1 shouldEqual result._2 - } - - "cacheable9" should "zio operation is ok with chunk" in { - val chunk = Chunk(Random.nextInt().toString, Random.nextInt().toString, Random.nextInt().toString) - - @cacheable(local = true) - def readIOFunction(id: Int, key: String): ZIO[Any, Throwable, Chunk[String]] = - ZIO.succeed(chunk) - - println(chunk) - val result = runtime.unsafeRun(for { - _ <- ZCaffeine.del("CacheableTest-readIOFunction") - method <- readIOFunction(1, "hello") - cache <- ZCaffeine.hGet[Chunk[String]]("CacheableTest-readIOFunction", "1-hello").map(_.getOrElse(Chunk.empty)) - } yield method -> cache) - result._1 shouldEqual result._2 - } -} diff --git a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CustomCacheableTest.scala b/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CustomCacheableTest.scala deleted file mode 100644 index a07def33..00000000 --- a/smt-cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/CustomCacheableTest.scala +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.caffeine - -import org.bitlap.cacheable.core.{ Cache, ZIOCache } -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import zio.ZIO - -import scala.util.Random -import zio.Task - -/** @author - * 梦境迷离 - * @since 2022/3/20 - * @version 1.0 - */ -class CustomCacheableTest extends AnyFlatSpec with Matchers { - - "create a custom cacheable by implicit" should "" in { - implicit def cache: ZIOCache[String] = new ZIOCache[String] { - override def getIfPresent( - business: => Task[String] - )(identities: List[String], args: List[_]): Task[String] = { - println("hello world!!") - business - } - } - - def readIOFunction(id: Int, key: String): Task[String] = { - val $result = ZIO.effect("hello world" + Random.nextInt()) - Cache($result)(List("UseCaseExample", "readIOFunction"), List(id, key)) - } - - val ret = zio.Runtime.default.unsafeRun(readIOFunction(1, "")) - ret.startsWith("hello world") shouldBe true - } -} diff --git a/smt-cacheable-redis/src/main/resources/reference.conf b/smt-cacheable-redis/src/main/resources/reference.conf deleted file mode 100644 index 14c405d0..00000000 --- a/smt-cacheable-redis/src/main/resources/reference.conf +++ /dev/null @@ -1,5 +0,0 @@ -redis { - host = "0.0.0.0" - port = 6379 - disabledLog = true -} \ No newline at end of file diff --git a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/Implicits.scala b/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/Implicits.scala deleted file mode 100644 index dabc5074..00000000 --- a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/Implicits.scala +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import org.bitlap.cacheable.core.{ Utils, ZIOCache, ZIOUpdateCache, ZStreamCache, ZStreamUpdateCache } -import zio.ZIO -import zio.schema.Schema -import zio.stream.ZStream -import zio.Chunk -import java.util.concurrent.atomic.AtomicLong -import org.bitlap.cacheable.core.UZStream -import zio.Task - -/** redis cache - * - * @author - * 梦境迷离 - * @version 1.0,2022/3/21 - */ -object Implicits { - - implicit def StreamUpdateCache[T: Schema]: ZStreamUpdateCache[T] = - new ZStreamUpdateCache[T] { - override def evict(business: => UZStream[T])(identities: List[String]): UZStream[T] = - for { - updateResult <- ZStream - .fromIterable(identities) - .flatMap(key => ZStream.fromEffect(ZRedisService.del(key))) *> business - _ <- Utils - .debugS(s"Redis ZStream update >>> identities:[$identities], updateResult:[$updateResult]") - .when(!ZRedisConfiguration.disabledLog) - } yield updateResult - } - - implicit def StreamReadCache[T: Schema]: ZStreamCache[T] = new ZStreamCache[T] { - override def getIfPresent( - business: => UZStream[T] - )(identities: List[String], args: List[_]): ZStream[Any, Throwable, T] = { - val key = cacheKey(identities) - val field = cacheField(args) - lazy val ret = business.runCollect.tap(r => ZRedisService.hSet[Chunk[T]](key, field, r)) - lazy val resultFun = (chunk: Chunk[T]) => if (chunk.isEmpty) ret else ZIO.succeed(chunk) - lazy val count = new AtomicLong(0L) - for { - // TODO fix it, cannot get case class from redis and not lock - cacheValue <- ZStream.fromEffect(ZRedisService.hGet[Chunk[T]](key, field)).map(_.getOrElse(Chunk.empty)) - _ <- Utils - .debugS(s"Redis ZStream getIfPresent >>> identity:[$key],field:[$field],cacheValue:[$cacheValue]") - .when(!ZRedisConfiguration.disabledLog) - ret <- ZStream.fromEffect(resultFun(cacheValue)) - result <- ZStream.fromIterable(ret) - _ <- - Utils - .debugS( - s"Redis ZStream getIfPresent >>> identity:[$key],field(${count.incrementAndGet()}):[$field],result:[$result]" - ) - .when(!ZRedisConfiguration.disabledLog) - } yield result - } - } - - implicit def UpdateCache[T: Schema]: ZIOUpdateCache[T] = new ZIOUpdateCache[T] { - override def evict(business: => Task[T])(identities: List[String]): Task[T] = - for { - updateResult <- ZIO.foreach_(identities)(key => ZRedisService.del(key)) *> business - _ <- Utils - .debug(s"Redis ZIO update >>> identities:[$identities], updateResult:[$updateResult]") - .when(!ZRedisConfiguration.disabledLog) - } yield updateResult - } - - implicit def ReadCache[T: Schema]: ZIOCache[T] = new ZIOCache[T] { - override def getIfPresent( - business: => Task[T] - )(identities: List[String], args: List[_]): Task[T] = { - val key = cacheKey(identities) - val field = cacheField(args) - for { - cacheValue <- ZRedisService.hGet[T](key, field) - _ <- Utils - .debug(s"Redis ZIO getIfPresent: identity:[$key], field:[$field], cacheValue:[$cacheValue]") - .when(!ZRedisConfiguration.disabledLog) - result <- cacheValue.fold(business.tap(r => ZRedisService.hSet[T](key, field, r).as(r)))(value => - ZIO.effectTotal(value) - ) - _ <- Utils - .debug(s"Redis ZIO getIfPresent >>> identity:[$key], field:[$field], result:[$result]") - .when(!ZRedisConfiguration.disabledLog) - } yield result - } - } -} diff --git a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala b/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala deleted file mode 100644 index c8662772..00000000 --- a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisConfiguration.scala +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import com.typesafe.config.{ Config, ConfigFactory } -import org.bitlap.cacheable.core.Utils -import zio.redis.{ Redis, RedisConfig, RedisError, RedisExecutor } -import zio.schema.codec.{ Codec, JsonCodec } -import zio.{ Has, Layer, ULayer, ZLayer } -import zio.logging.Logging - -/** redis configuration - * - * @author - * 梦境迷离 - * @since 2022/1/10 - * @version 2.0 - */ -object ZRedisConfiguration { - - private lazy val conf: Config = ConfigFactory.load("reference.conf") - private lazy val custom: Config = ConfigFactory.load("application.conf").withFallback(conf) - private lazy val redisConf: RedisConfig = RedisConfig(custom.getString("redis.host"), custom.getInt("redis.port")) - - private[redis] lazy val disabledLog: Boolean = custom.getBoolean("redis.disabledLog") - - private val codec: ULayer[Has[Codec]] = ZLayer.succeed[Codec](JsonCodec) - - lazy val redisLayer: Layer[RedisError.IOError, ZRedisCacheService] = - (((if (disabledLog) Logging.ignore else Utils.logLayer) ++ ZLayer.succeed(redisConf)) >>> - RedisExecutor.live ++ ZRedisConfiguration.codec) >>> - (Redis.live >>> (r => ZRedisLive(r)).toLayer) -} diff --git a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisLive.scala b/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisLive.scala deleted file mode 100644 index 1160ea8b..00000000 --- a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisLive.scala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import zio.{ redis, Has, ULayer, ZIO, ZLayer } -import zio.redis.{ Redis, RedisError } -import zio.schema.Schema - -/** @author - * 梦境迷离 - * @see - * https://zio.dev/version-1.x/datatypes/contextual/#module-pattern-20 - * @version 2.0,2022/1/17 - */ -case class ZRedisLive(private val rs: Redis) extends ZRedisService { - - private lazy val redisLayer: ULayer[Has[Redis]] = ZLayer.succeed(rs) - - override def del(key: String): ZIO[ZRedisCacheService, RedisError, Long] = - redis.del(key).orDie.provideLayer(redisLayer) - - override def hSet[T: Schema](key: String, field: String, value: T): ZIO[ZRedisCacheService, RedisError, Long] = - redis.hSet[String, String, T](key, field -> value).provideLayer(redisLayer) - - override def hGet[T: Schema](key: String, field: String): ZIO[ZRedisCacheService, RedisError, Option[T]] = - redis.hGet(key, field).returning[T].provideLayer(redisLayer) - - override def hGetAll[T: Schema](key: String): ZIO[ZRedisCacheService, RedisError, Map[String, T]] = - redis.hGetAll(key).returning[String, T].provideLayer(redisLayer) -} diff --git a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisService.scala b/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisService.scala deleted file mode 100644 index 3c88c35b..00000000 --- a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/ZRedisService.scala +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import zio.redis.RedisError -import zio.schema.Schema -import zio.{ IO, Layer, ZIO } - -/** Redis service. - * - * @author - * 梦境迷离 - * @version 2.0,2022/1/10 - */ -trait ZRedisService { - - /** @param key - * @return - * Long - */ - def del(key: String): ZIO[ZRedisCacheService, RedisError, Long] - - /** @param key - * @param field - * @param value - * @return - * Long - */ - def hSet[T: Schema](key: String, field: String, value: T): ZIO[ZRedisCacheService, RedisError, Long] - - /** @param key - * @param field - * @return - * Option[T] - */ - def hGet[T: Schema](key: String, field: String): ZIO[ZRedisCacheService, RedisError, Option[T]] - - /** @param key - * @tparam T - * @return - */ - def hGetAll[T: Schema](key: String): ZIO[ZRedisCacheService, RedisError, Map[String, T]] - -} - -object ZRedisService { - - lazy val zioRedisLayer: Layer[RedisError.IOError, ZRedisCacheService] = ZRedisConfiguration.redisLayer - - def del(key: String)(implicit - layer: Layer[RedisError.IOError, ZRedisCacheService] = zioRedisLayer - ): IO[RedisError, Long] = - ZIO.serviceWith[ZRedisService](_.del(key)).provideLayer(layer) - - def hSet[T: Schema](key: String, field: String, value: T)(implicit - layer: Layer[RedisError.IOError, ZRedisCacheService] = zioRedisLayer - ): IO[RedisError, Long] = - ZIO.serviceWith[ZRedisService](_.hSet[T](key, field, value)).provideLayer(layer) - - def hGet[T: Schema](key: String, field: String)(implicit - layer: Layer[RedisError.IOError, ZRedisCacheService] = zioRedisLayer - ): IO[RedisError, Option[T]] = - ZIO.serviceWith[ZRedisService](_.hGet[T](key, field)).provideLayer(layer) -} diff --git a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/redis.scala b/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/redis.scala deleted file mode 100644 index 95e3aa47..00000000 --- a/smt-cacheable-redis/src/main/scala/org/bitlap/cacheable/redis/redis.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable - -import zio.Has - -/** @author - * 梦境迷离 - * @since 2022/2/27 - * @version 1.0 - */ -package object redis { - - type ZRedisCacheService = Has[ZRedisService] - -} diff --git a/smt-cacheable-redis/src/test/resources/application.conf b/smt-cacheable-redis/src/test/resources/application.conf deleted file mode 100644 index 2de9d244..00000000 --- a/smt-cacheable-redis/src/test/resources/application.conf +++ /dev/null @@ -1,5 +0,0 @@ -redis { - host = "0.0.0.0" - port = 6379 - disabledLog = false -} \ No newline at end of file diff --git a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheEvictTest.scala b/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheEvictTest.scala deleted file mode 100644 index bb6d3393..00000000 --- a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheEvictTest.scala +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import org.bitlap.cacheable.core.cacheEvict -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import zio.ZIO -import zio.stream.ZStream - -import scala.util.Random - -/** @author - * 梦境迷离 - * @since 2022/3/19 - * @version 1.0 - */ -class CacheEvictTest extends AnyFlatSpec with Matchers { - - val runtime = zio.Runtime.default - - // write readStreamFunction1 method , otherwise: The specified method: `readStreamFunction1` does not exist in enclosing class: `CacheEvictTest`! - def readStreamFunction1: String = "hello world" - - def readStreamFunction: String = "hello world" - - def readIOFunction: String = "hello world" - - val readIOMethodName = "readIOFunction" - val readStreamMethodName = "readStreamFunction" - - "cacheEvict1" should "ok" in { - @cacheEvict(local = false, values = List("readStreamFunction1")) - def updateStreamFunction1(id: Int, key: String): ZStream[Any, Throwable, String] = - ZStream.fromEffect(ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}")) - - @cacheEvict(local = false, values = List("readStreamFunction1")) - def updateAliasStreamFunction2(id: Int, key: String): zio.stream.Stream[Throwable, String] = - ZStream.fromEffect(ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}")) - } - - "cacheEvict2" should "ok" in { - @cacheEvict(local = false, values = List("readStreamFunction1")) - def updateFunction(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - } - - "cacheEvict3" should "String cannot compile" in { - """ - | @cacheEvict(local = false, values = List("readStreamFunction1")) - | def updateFunction(id: Int, key: String): String = { - | s"hello world--$id-$key-${Random.nextInt()}" - | } - |""".stripMargin shouldNot compile - } - - "cacheEvict4" should "need specified type, otherwise cannot compile" in { - """ - | @cacheEvict(local = false, values = List("readStreamFunction1")) - | def updateFunction(id: Int, key: String) = { - | s"hello world--$id-$key-${Random.nextInt()}" - | } - |""".stripMargin shouldNot compile - } - - "cacheEvict5" should "compile failed when function name not found" in { - """ - | @cacheEvict(local = false, values = List("1212")) - | def updateFunction(id: Int, key: String): ZIO[Any, Throwable, String] = { - | ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - | } - |""".stripMargin shouldNot compile - } - - "cacheEvict6" should "expected annotation pattern" in { - @cacheEvict(local = false, values = List("readStreamFunction1")) - def updateFunction1(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - - @cacheEvict(local = false, values = List("readStreamFunction1")) - def updateFunction2(id: Int, key: String): ZIO[Any, Throwable, String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - } - - "cacheEvict7" should "unexpected annotation pattern" in { - """ - | @cacheEvict(values = List("readStreamFunction1"), local = true) - | def updateFunction1(id: Int, key: String): ZIO[Any, Throwable, String] = { - | ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - | } - | - | @cacheEvict(false, values = List("readStreamFunction1")) - | def updateFunction2(id: Int, key: String): ZIO[Any, Throwable, String] = { - | ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - | } - |""".stripMargin shouldNot compile - } - -} diff --git a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheValue.scala b/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheValue.scala deleted file mode 100644 index 53157550..00000000 --- a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheValue.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis -import zio.schema.{ DeriveSchema, Schema } - -// The case class should be here, not in the test -case class CacheValue(i: String) - -object CacheValue { - - implicit val cacheValueSchema: Schema[CacheValue] = DeriveSchema.gen[CacheValue] -} diff --git a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheableTest.scala b/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheableTest.scala deleted file mode 100644 index e6cfb5d8..00000000 --- a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CacheableTest.scala +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import org.bitlap.cacheable.core.cacheable -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import zio.stream.ZStream -import zio.{ Task, ZIO } -import zio.Chunk - -import scala.util.Random - -/** @author - * 梦境迷离 - * @since 2021/8/7 - * @version 1.0 - */ -class CacheableTest extends AnyFlatSpec with Matchers { - - val runtime = zio.Runtime.default - val readIOMethodName = "readIOFunction" - - "cacheable1" should "ok" in { - @cacheable(local = false) - def readStreamFunction1(id: Int, key: String): ZStream[Any, Throwable, String] = - ZStream.fromEffect(ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}")) - } - - "cacheable2" should "expected annotation pattern" in { - @cacheable(false) - def readFunction2(id: Int, key: String): Task[String] = - ZIO.effect(s"hello world--$id-$key-${Random.nextInt()}") - } - - "cacheable3" should "ok when return type is case class" in { - @cacheable(local = false) - def readEntityFunction(id: Int, key: String): ZIO[Any, Throwable, CacheValue] = - ZIO.effect(CacheValue(Random.nextInt() + "")) - } - - "cacheable4" should "zstream operation is ok with redis" in { - val chunk = Chunk(Random.nextInt().toString, Random.nextInt().toString, Random.nextInt().toString) - - @cacheable(local = false) - def readStreamFunction(id: Int, key: String): ZStream[Any, Throwable, String] = - ZStream.fromIterable(chunk) - - println(chunk) - val result = runtime.unsafeRun(for { - _ <- ZRedisService.del("CacheableTest-readStreamFunction") - method <- readStreamFunction(1, "hello").runCollect - cache <- ZRedisService.hGet[Chunk[String]]("CacheableTest-readStreamFunction", "1-hello") - } yield method -> cache.getOrElse(Chunk.empty)) - result._1 shouldEqual result._2 - } - - "cacheable5" should "entity zstream is ok with redis" in { - val cacheValue = CacheValue(Random.nextInt().toString) - - @cacheable(local = false) - def readEntityStreamFunction(id: Int, key: String): ZStream[Any, Throwable, CacheValue] = - ZStream.fromEffect(ZIO.effect(cacheValue)) - - val result = runtime.unsafeRun(for { - _ <- ZRedisService.del("CacheableTest-readEntityStreamFunction") - method <- readEntityStreamFunction(1, "hello").runHead - } yield method) - - result shouldEqual Some(cacheValue) - } - - "cacheable6" should "entity zio is ok with redis" in { - val cacheValue = CacheValue(Random.nextInt().toString) - - @cacheable(local = false) - def readEntityIOFunction(id: Int, key: String): ZIO[Any, Throwable, CacheValue] = - ZIO.effect(cacheValue) - - val result = runtime.unsafeRun(for { - _ <- ZRedisService.del("CacheableTest-readEntityIOFunction") - method <- readEntityIOFunction(1, "hello") - cache <- ZRedisService.hGet[CacheValue]("CacheableTest-readEntityIOFunction", "1-hello") - } yield Some(method) -> cache) - - result._1 shouldEqual result._2 - - } -} diff --git a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CustomCacheableTest.scala b/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CustomCacheableTest.scala deleted file mode 100644 index 986af0e1..00000000 --- a/smt-cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/CustomCacheableTest.scala +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.redis - -import org.bitlap.cacheable.core.{ Cache, ZIOCache } -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers -import zio.ZIO -import zio.schema.Schema.Primitive -import zio.schema.{ Schema, StandardType } -import zio.Task - -import scala.util.Random - -/** @author - * 梦境迷离 - * @since 2022/3/20 - * @version 1.0 - */ -class CustomCacheableTest extends AnyFlatSpec with Matchers { - - "create a custom cacheable by implicit" should "" in { - implicit val schema: Schema[String] = Primitive(StandardType.StringType) - - implicit def cache[T: Schema]: ZIOCache[String] = new ZIOCache[String] { - override def getIfPresent( - business: => Task[String] - )(identities: List[String], args: List[_]): ZIO[Any, Throwable, String] = { - println("hello world!!") - business - } - } - - def readIOFunction(id: Int, key: String): ZIO[Any, Throwable, String] = { - val $result = ZIO.effect("hello world" + Random.nextInt()) - Cache($result)(List("UseCaseExample", "readIOFunction"), List(id, key)) - } - - val ret = zio.Runtime.default.unsafeRun(readIOFunction(1, "")) - ret.startsWith("hello world") shouldBe true - } -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Cache.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Cache.scala deleted file mode 100644 index 09a5fe27..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Cache.scala +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core -import zio.Task - -/** A distributed cache for zio. - * - * @tparam Z - * The result type of the function that returns the ZIO or ZStream effect. - */ -trait Cache[T, F[_]] { - - /** Get cache or getAndSet cache from Cache while read data. - * - * @param business - * The function that returns the ZIO or ZStream effect. - * @param identities - * Append all strings for cache key. - * @param args - * The parameters of the business function. - * @return - * The result fo the business function. - */ - def getIfPresent(business: => F[T])(identities: List[String], args: List[_]): F[T] - - /** Evict cache while data update. - * - * @param business - * The function that returns the ZIO or ZStream effect. - * @param identities - * Append all strings for cache key. - * @return - * The result fo the business function. - */ - def evict(business: => F[T])(identities: List[String]): F[T] - - /** Build a string for cache key. - * - * @param keys - * Append all strings for hash key - * @return - * string - */ - def cacheKey(keys: List[String]): String = keys.mkString("-") - - /** Build a string for cache field. - * - * @param args - * The parameters of the business function. - * @return - * hash field - */ - def cacheField(args: List[_]): String = args.map(_.toString).mkString("-") - -} - -object Cache { - - def apply[T](business: => UZStream[T])(identities: List[String], args: List[_])(implicit - streamCache: ZStreamCache[T] - ): UZStream[T] = - streamCache.getIfPresent(business)(identities, args) - - def apply[T](business: => Task[T])(identities: List[String], args: List[_])(implicit - cache: ZIOCache[T] - ): Task[T] = - cache.getIfPresent(business)(identities, args) - - def evict[T](business: => UZStream[T])(identities: List[String])(implicit - streamCache: ZStreamUpdateCache[T] - ): UZStream[T] = - streamCache.evict(business)(identities) - - def evict[T](business: => Task[T])(identities: List[String])(implicit - cache: ZIOUpdateCache[T] - ): Task[T] = - cache.evict(business)(identities) - -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Utils.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Utils.scala deleted file mode 100644 index 608b4a52..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/Utils.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -import zio.clock.Clock -import zio.console.Console -import zio.logging.{ LogFormat, LogLevel, Logger, Logging } -import zio.stream.{ UStream, ZStream } -import zio.{ UIO, ULayer, URLayer, ZIO } -import zio.blocking.Blocking - -/** Internal Utils - * - * @author - * 梦境迷离 - * @version 1.0,2022/3/18 - */ -object Utils { - - lazy val loggingLayer: URLayer[Console with Clock, Logging] = - Logging.console( - logLevel = LogLevel.Debug, - format = LogFormat.ColoredLogFormat() - ) >>> Logging.withRootLoggerName("bitlap-smt-cacheable") - - lazy val logLayer: ULayer[Logging] = (Console.live ++ Clock.live) >>> loggingLayer - - def debug(msg: => String): UIO[Unit] = - ZIO.serviceWith[Logger[String]](_.debug(msg)).provideLayer(logLayer) - - def debugS(msg: => String): UStream[Unit] = - ZStream.fromEffect(debug(msg)) - - def effectBlocking[T](action: => T): ZIO[Any, Throwable, T] = - ZIO.serviceWith[Blocking.Service](_.effectBlocking(action)).provideLayer(Blocking.live) -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOCache.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOCache.scala deleted file mode 100644 index 863b5363..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOCache.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -import zio.Task - -/** Redis Cache for ZIO. - * - * @author - * 梦境迷离 - * @version 2.0,2022/3/18 - */ -trait ZIOCache[T] extends Cache[T, Task] { - - override def getIfPresent(business: => Task[T])(identities: List[String], args: List[_]): Task[T] - - override def evict(business: => Task[T])(identities: List[String]): Task[T] = - throw new UnsupportedOperationException() - - override def toString: String = "ZIOCache" - -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOUpdateCache.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOUpdateCache.scala deleted file mode 100644 index 3c4e9b6c..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZIOUpdateCache.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -import zio.Task - -/** Redis Update Cache for ZIO. - * - * @author - * 梦境迷离 - * @version 2.0,2022/3/18 - */ -trait ZIOUpdateCache[T] extends Cache[T, Task] { - - override final def getIfPresent(business: => Task[T])(identities: List[String], args: List[_]): Task[T] = - throw new UnsupportedOperationException() - - override def evict(business: => Task[T])(identities: List[String]): Task[T] - - override def toString: String = "ZIOUpdateCache" - -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamCache.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamCache.scala deleted file mode 100644 index fa8ecad0..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamCache.scala +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -/** Redis Cache for ZStream. - * - * @author - * 梦境迷离 - * @version 2.0,2022/3/19 - */ -trait ZStreamCache[T] extends Cache[T, UZStream] { - - override def getIfPresent(business: => UZStream[T])(identities: List[String], args: List[_]): UZStream[T] - - override final def evict(business: => UZStream[T])(identities: List[String]): UZStream[T] = - throw new UnsupportedOperationException() - - override def toString: String = "ZStreamCache" - -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamUpdateCache.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamUpdateCache.scala deleted file mode 100644 index 2d057e6c..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/ZStreamUpdateCache.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -/** Redis Update Cache for ZStream. - * - * @author - * 梦境迷离 - * @version 2.0,2022/3/19 - */ -trait ZStreamUpdateCache[T] extends Cache[T, UZStream] { - - override final def getIfPresent( - business: => UZStream[T] - )(identities: List[String], args: List[_]): UZStream[T] = throw new UnsupportedOperationException() - - override def evict(business: => UZStream[T])(identities: List[String]): UZStream[T] - - override def toString: String = "ZStreamUpdateCache" - -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheEvict.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheEvict.scala deleted file mode 100644 index c251eb73..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheEvict.scala +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -import org.bitlap.cacheable.core.macros.CacheEvictMacro - -import scala.annotation.{ compileTimeOnly, StaticAnnotation } - -/** A distributed cache for zio. - * - * @author - * 梦境迷离 - * @param local - * Whether to enable local cache by caffeine. Must be a named parameter. - * @param values - * Indicates which caches the purge operation occurs on. Must be a named parameter. - * @since 2022/3/18 - * @version 1.0 - */ -@compileTimeOnly("enable macro to expand macro annotations") -final class cacheEvict(local: Boolean = true, values: List[String] = Nil) extends StaticAnnotation { - def macroTransform(annottees: Any*): Any = macro CacheEvictMacro.CacheEvictProcessor.impl -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheable.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheable.scala deleted file mode 100644 index e5b1e19d..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/cacheable.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core - -import org.bitlap.cacheable.core.macros.CacheableMacro.CacheableProcessor - -import scala.annotation.{ compileTimeOnly, StaticAnnotation } - -/** A distributed cache for zio. - * - * @author - * 梦境迷离 - * @param local - * Whether to enable local cache by caffeine. - * @since 2022/3/18 - * @version 1.0 - */ -@compileTimeOnly("enable macro to expand macro annotations") -final class cacheable(local: Boolean = true) extends StaticAnnotation { - def macroTransform(annottees: Any*): Any = macro CacheableProcessor.impl -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/AbstractMacroProcessor.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/AbstractMacroProcessor.scala deleted file mode 100644 index 01b24070..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/AbstractMacroProcessor.scala +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core.macros - -import java.time.ZonedDateTime -import java.time.format.DateTimeFormatter -import scala.annotation.tailrec -import scala.collection.mutable.ListBuffer -import scala.reflect.macros.whitebox - -/** @author - * 梦境迷离 - * @since 2022/3/19 - * @version 1.0 - */ -abstract class AbstractMacroProcessor(val c: whitebox.Context) { - - import c.universe._ - - /** Output ast result. - * - * @param force - * @param resTree - */ - def printTree(force: Boolean, resTree: Tree): Unit = - c.info( - c.enclosingPosition, - s"\n###### Time: ${ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)} " + - s"Expanded macro start ######\n" + resTree.toString() + "\n###### Expanded macro end ######\n", - force = false - ) - - /** Find the specified method Name in the enclosing class definition. - * - * @param t - * @return - * Return a optional [[scala.reflect.api.Names#TermName]] - */ - def findDefDefInEnclosingClass(t: Name): Option[TermName] = - getDefDefInEnclosingClass.find(_.decodedName.toString == t.decodedName.toString) - - /** Find all method Name in the enclosing class definition. - * - * @return - * Return a sequence of [[scala.reflect.api.Names#TermName]] - */ - def getDefDefInEnclosingClass: Set[TermName] = { - val buffer = ListBuffer[TermName]() - - @tailrec - def doFind(trees: List[Tree]): Option[TermName] = trees match { - case Nil => None - case tree :: tail => - tree match { - case DefDef(_, name, _, _, _, _) => - c.info( - c.enclosingPosition, - s"Method: `${name.decodedName.toString}` in enclosing class: `$getEnclosingClassName`.", - force = false - ) - buffer.append(name) - doFind(tail) - case _ => - doFind(tail) - } - } - - c.enclosingClass match { - case ClassDef(_, _, _, Template(_, _, body)) => doFind(body) - case ModuleDef(_, _, Template(_, _, body)) => doFind(body) - } - buffer.result().toSet - } - - /** Get enclosing class name - * - * @return - */ - def getEnclosingClassName: String = - c.enclosingClass match { - case ClassDef(_, name, _, Template(_, _, _)) => name.decodedName.toString - case ModuleDef(_, name, Template(_, _, _)) => name.decodedName.toString - } -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheEvictMacro.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheEvictMacro.scala deleted file mode 100644 index 5ab7dc7d..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheEvictMacro.scala +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core.macros - -import scala.reflect.macros.whitebox - -/** Evict cache - * - * @author - * 梦境迷离 - * @since 2022/3/19 - * @version 1.0 - */ -object CacheEvictMacro { - - class CacheEvictProcessor(override val c: whitebox.Context) extends AbstractMacroProcessor(c) { - - import c.universe._ - - private lazy val resultValName: c.universe.TermName = TermName("$result") - private lazy val argsValName: c.universe.TermName = TermName("$args") - - private val parameters: Tuple2[Boolean, List[String]] = - c.prefix.tree match { - case q"new cacheEvict(local=$local, values=$values)" => - Tuple2( - c.eval(c.Expr[Boolean](c.untypecheck(local.asInstanceOf[Tree].duplicate))), - c.eval(c.Expr[List[String]](c.untypecheck(values.asInstanceOf[Tree].duplicate))) - ) - case q"new cacheEvict(local=$local)" => - Tuple2( - c.eval(c.Expr[Boolean](c.untypecheck(local.asInstanceOf[Tree].duplicate))), - Nil - ) - case q"new cacheEvict(values=$values)" => - Tuple2( - true, - c.eval(c.Expr[List[String]](c.untypecheck(values.asInstanceOf[Tree].duplicate))) - ) - case q"new cacheEvict($local, $values)" => - Tuple2( - c.eval(c.Expr[Boolean](c.untypecheck(local.asInstanceOf[Tree].duplicate))), - c.eval(c.Expr[List[String]](c.untypecheck(values.asInstanceOf[Tree].duplicate))) - ) - case q"new cacheEvict()" => - Tuple2( - true, - Nil - ) - case _ => - c.abort(c.enclosingPosition, "Unexpected annotation pattern!") - } - - def impl(annottees: c.universe.Expr[Any]*): c.universe.Expr[Any] = { - val resTree = annottees.map(_.tree) match { - case (defDef @ DefDef(mods, name, tparams, vparamss, tpt, _)) :: Nil => - if (tpt.isEmpty) { - c.abort(c.enclosingPosition, "The return type of the method is not specified!") - } - val tp = c.typecheck(tq"$tpt", c.TYPEmode).tpe - if (!(tp <:< typeOf[zio.ZIO[_, _, _]]) && !(tp <:< typeOf[zio.stream.ZStream[_, _, _]])) { - c.abort( - c.enclosingPosition, - s"The return type of the method not support type: `${tp.typeSymbol.name.toString}`!" - ) - } - val enclosingClassName = getEnclosingClassName - parameters._2.toSet[String].foreach { defName => - if (findDefDefInEnclosingClass(TermName(defName)).isEmpty) { - c.abort( - c.enclosingPosition, - s"The specified method: `$defName` does not exist in enclosing class: `$enclosingClassName`!" - ) - } - } - val identities = if (parameters._2.isEmpty) { - getDefDefInEnclosingClass - .map(_.decodedName.toString) - .filter(_ != "") - .map(p => enclosingClassName + "-" + p) - } else { - parameters._2.toSet.map(p => enclosingClassName + "-" + p) - } - val importExpr = - if (parameters._1) q"import _root_.org.bitlap.cacheable.caffeine.Implicits._" - else q"import _root_.org.bitlap.cacheable.redis.Implicits._" - c.info( - c.enclosingPosition, - s"""These methods will remove from cache: $identities, key prefix is: $enclosingClassName, mode is: ${if ( - parameters._1 - ) "local" - else "redis"}""", - true - ) - val newBody = - q""" - val $resultValName = ${defDef.rhs} - val $argsValName = ${identities.toList} - $importExpr - org.bitlap.cacheable.core.Cache.evict($resultValName)(${argsValName}) - """ - DefDef(mods, name, tparams, vparamss, tpt, newBody) - - } - printTree(force = false, resTree) - c.Expr[Any](resTree) - } - } -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheableMacro.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheableMacro.scala deleted file mode 100644 index 3e244c86..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/macros/CacheableMacro.scala +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable.core.macros - -import scala.reflect.macros.whitebox - -/** GetAndSet cache - * - * @author - * 梦境迷离 - * @since 2022/3/18 - * @version 1.0 - */ -object CacheableMacro { - - class CacheableProcessor(override val c: whitebox.Context) extends AbstractMacroProcessor(c) { - - import c.universe._ - - private lazy val resultValName: c.universe.TermName = TermName("$result") - private lazy val keyValName: c.universe.TermName = TermName("$key") - - protected val local: Boolean = - c.prefix.tree match { - case q"new cacheable(local=$local)" => - c.eval(c.Expr[Boolean](c.untypecheck(local.asInstanceOf[Tree].duplicate))) - case q"new cacheable($local)" => c.eval(c.Expr[Boolean](c.untypecheck(local.asInstanceOf[Tree].duplicate))) - case q"new cacheable()" => true - } - - private def getParamsName(vparamss: List[List[ValDef]]): List[List[TermName]] = - vparamss.map(_.map(_.name)) - - def impl(annottees: c.universe.Expr[Any]*): c.universe.Expr[Any] = { - val resTree = annottees.map(_.tree) match { - case (defDef @ DefDef(mods, name, tparams, vparamss, tpt, _)) :: Nil => - if (tpt.isEmpty) { - c.abort(c.enclosingPosition, "The return type of the method is not specified!") - } - val tp = c.typecheck(tq"$tpt", c.TYPEmode).tpe - if (!(tp <:< typeOf[zio.ZIO[_, _, _]]) && !(tp <:< typeOf[zio.stream.ZStream[_, _, _]])) { - c.abort( - c.enclosingPosition, - s"The return type of the method not support type: `${tp.typeSymbol.name.toString}`!" - ) - } - val importExpr = - if (local) q"import _root_.org.bitlap.cacheable.caffeine.Implicits._" - else q"import _root_.org.bitlap.cacheable.redis.Implicits._" - val newBody = - q""" - val $resultValName = ${defDef.rhs} - val $keyValName = _root_.scala.List($getEnclosingClassName, ${name.decodedName.toString}) - $importExpr - org.bitlap.cacheable.core.Cache($resultValName)($keyValName, ..${getParamsName(vparamss)}) - """ - DefDef(mods, name, tparams, vparamss, tpt, newBody) - - } - printTree(force = false, resTree) - c.Expr[Any](resTree) - } - } -} diff --git a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/package.scala b/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/package.scala deleted file mode 100644 index 5c6044aa..00000000 --- a/smt-cacheable/src/main/scala/org/bitlap/cacheable/core/package.scala +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 bitlap - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.bitlap.cacheable - -/** @author - * 梦境迷离 - * @version 1.0,2022/7/22 - */ -package object core { - type UZStream[+A] = zio.stream.Stream[Throwable, A] -} From 47269317d23a5004f480270bb9ab0cdb2b71e7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=A2=83=E8=BF=B7=E7=A6=BB?= Date: Fri, 12 Aug 2022 14:21:56 +0800 Subject: [PATCH 2/3] remove unavailable modules --- build.sbt | 6 +++--- project/plugins.sbt | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.sbt b/build.sbt index 0053c275..a271685a 100644 --- a/build.sbt +++ b/build.sbt @@ -8,9 +8,9 @@ ThisBuild / resolvers ++= Seq( "New snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots/" ) -lazy val scala212 = "2.12.14" -lazy val scala211 = "2.11.12" -lazy val scala213 = "2.13.8" +lazy val scala212 = "2.12.14" +lazy val scala211 = "2.11.12" +lazy val scala213 = "2.13.8" lazy val scalatestVersion = "3.2.13" lazy val scalaLoggingVersion = "3.9.5" diff --git a/project/plugins.sbt b/project/plugins.sbt index b281af2e..939ab16f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.13") -addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") -addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.7.0") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.13") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.7.0") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1") From e5c3d296c83b59dc0f83c2d1c3d30dbe4e0c2361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=A2=83=E8=BF=B7=E7=A6=BB?= Date: Fri, 12 Aug 2022 16:23:10 +0800 Subject: [PATCH 3/3] fix --- smt-cache/src/main/scala/org/bitlap/cache/CacheAdapter.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smt-cache/src/main/scala/org/bitlap/cache/CacheAdapter.scala b/smt-cache/src/main/scala/org/bitlap/cache/CacheAdapter.scala index 522cce1c..9d35534b 100644 --- a/smt-cache/src/main/scala/org/bitlap/cache/CacheAdapter.scala +++ b/smt-cache/src/main/scala/org/bitlap/cache/CacheAdapter.scala @@ -46,8 +46,8 @@ trait CacheAdapter[V] { object CacheAdapter { - def adapted[V](cacheType: CacheStrategy): CacheAdapter[V] = - cacheType match { + def adapted[V](cacheStrategy: CacheStrategy): CacheAdapter[V] = + cacheStrategy match { case CacheStrategy.Lru(maxSize) => new LruHashMapCacheAdapter( Collections.synchronizedMap(new java.util.LinkedHashMap[String, V](16, 0.75f, true) {