Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Scala Macro Tools
提交
0b1b7010
S
Scala Macro Tools
项目概览
梦境迷离
/
Scala Macro Tools
上一次同步 1 年多
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Scala Macro Tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0b1b7010
编写于
3月 22, 2022
作者:
梦境迷离
提交者:
GitHub
3月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add examples (#161)
上级
207d4e8e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
77 addition
and
59 deletion
+77
-59
.github/workflows/ScalaCI.yml
.github/workflows/ScalaCI.yml
+3
-3
build.sbt
build.sbt
+20
-5
examples/scala2-12/src/main/scala/org/bitlap/tools/CacheExample.scala
...la2-12/src/main/scala/org/bitlap/tools/CacheExample.scala
+11
-25
examples/scala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala
...cala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala
+14
-0
examples/scala2-13/src/main/scala/org/bitlap/tools/CacheExample.scala
...la2-13/src/main/scala/org/bitlap/tools/CacheExample.scala
+12
-26
examples/scala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala
...cala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala
+17
-0
未找到文件。
.github/workflows/ScalaCI.yml
浏览文件 @
0b1b7010
...
...
@@ -23,11 +23,11 @@ jobs:
-
name
:
Cache scala dependencies
uses
:
coursier/cache-action@v6
-
name
:
Build
run
:
sbt +compile
-
name
:
Checking headers
run
:
sbt headerCheckAll
-
name
:
Build and Publish to Local
run
:
sbt +publishLocal
test
:
runs-on
:
ubuntu-latest
...
...
build.sbt
浏览文件 @
0b1b7010
...
...
@@ -12,7 +12,7 @@ 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.
3.4
"
lazy
val
lastVersionForExamples
=
"0.
4.0-SNAPSHOT
"
lazy
val
commonSettings
=
Seq
(
...
...
@@ -132,29 +132,44 @@ lazy val root = (project in file(".")).aggregate(tools, `cacheable-core`, `cache
.settings(
publishArtifact := false,
publish / skip := true,
headerLicense := Some(HeaderLicense.MIT("2022", "bitlap"))
// otherwise headerCheckAll will failed
headerLicense := Some(HeaderLicense.MIT("2022", "bitlap"))
)
lazy val `scala2
-
13
` = (project in file("examples/scala2-13")).settings(scalaVersion := scala213)
.settings(libraryDependencies ++= Seq(
"org.bitlap" %% "scala-macro-tools" % lastVersionForExamples,
"org.bitlap" %% "smt-tools" % lastVersionForExamples,
"org.bitlap" %% "smt-cacheable-core" % lastVersionForExamples,
"org.bitlap" %% "smt-cacheable-redis" % lastVersionForExamples,
"org.bitlap" %% "smt-cacheable-caffeine" % lastVersionForExamples,
)).settings(
publish / skip := true,
excludeDependencies ++= Seq(
InclExclRule("com.google.protobuf")
),
Compile / scalacOptions += "-Ymacro-annotations"
)
lazy val `scala2
-
12
` = (project in file("examples/scala2-12")).settings(scalaVersion := scala212)
.settings(libraryDependencies ++= Seq(
"org.bitlap" %% "scala-macro-tools" % lastVersionForExamples,
"org.bitlap" %% "smt-tools" % lastVersionForExamples,
"org.bitlap" %% "smt-cacheable-core" % lastVersionForExamples,
"org.bitlap" %% "smt-cacheable-redis" % lastVersionForExamples,
"org.bitlap" %% "smt-cacheable-caffeine" % lastVersionForExamples
)).settings(
publish / skip := true,
excludeDependencies ++= Seq(
InclExclRule("com.google.protobuf")
),
paradise()
)
lazy val `scala2
-
11
`
=
(
project
in
file
(
"examples/scala2-11"
)).
settings
(
scalaVersion
:=
scala211
)
.
settings
(
libraryDependencies
++=
Seq
(
"org.bitlap"
%%
"s
cala-macro
-tools"
%
lastVersionForExamples
,
"org.bitlap"
%%
"s
mt
-tools"
%
lastVersionForExamples
,
)).
settings
(
excludeDependencies
++=
Seq
(
InclExclRule
(
"com.google.protobuf"
)
),
publish
/
skip
:=
true
,
paradise
()
)
...
...
cacheable-redis/src/test/scala/org/bitlap/cacheable/redis/UseCas
eExample.scala
→
examples/scala2-12/src/main/scala/org/bitlap/tools/Cach
eExample.scala
浏览文件 @
0b1b7010
...
...
@@ -19,13 +19,13 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package
org.bitlap.
cacheable.redi
s
package
org.bitlap.
tool
s
import
org.bitlap.cacheable.core.
{
Cache
,
LogUtils
}
import
org.bitlap.cacheable.core.
{
cacheable
,
Cache
,
LogUtils
}
import
org.bitlap.cacheable.redis.Implicits._
import
zio.
{
ExitCode
,
UIO
,
URIO
,
ZIO
}
import
zio.console.putStrLn
import
zio.stream.ZStream
import
zio.
{
ExitCode
,
UIO
,
URIO
,
ZIO
}
import
scala.util.Random
...
...
@@ -35,8 +35,9 @@ import scala.util.Random
* @author 梦境迷离
* @version 1.0,2022/3/18
*/
object
UseCas
eExample
extends
zio
.
App
{
object
Cach
eExample
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
))
...
...
@@ -47,36 +48,21 @@ object UseCaseExample extends zio.App {
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readStreamFunction"
),
List
(
id
,
key
))
}
def
readFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
String
]
=
{
val
$result
=
ZIO
.
effect
(
"hello world"
+
Random
.
nextInt
())
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readFunction"
),
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"
))
}
def
updateFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
String
]
=
{
val
$result
=
ZIO
.
effect
(
"hello world"
+
Random
.
nextInt
())
Cache
.
evict
(
$result
)(
List
(
"readFunction1"
,
"readFunction2"
))
}
def
readEntityFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
CacheValue
]
=
{
val
$result
=
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
))
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readEntityFunction"
),
List
(
id
,
key
))
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
]
=
{
val
$result
=
ZStream
.
fromEffect
(
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
)))
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readStreamEntityFunction"
),
List
(
id
,
key
))
ZStream
.
fromEffect
(
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
)))
}
override
def
run
(
args
:
List
[
String
])
:
URIO
[
zio.ZEnv
,
ExitCode
]
=
(
for
{
ret
<-
readStreamEntityFunction
(
1
,
"hello-world"
).
runHead
cache
=
zio
.
Runtime
.
default
.
unsafeRun
(
ZRedisService
.
hGet
[
CacheValue
](
"UseCaseExample-readStreamEntityFunction"
,
"1-hello-world"
))
_
<-
LogUtils
.
debug
(
s
"${
ret.toString} $cache
"
)
cache1
<-
readStreamEntityFunction
(
1
,
"hello-world"
).
runHead
cache
2
<-
updateStreamFunction
(
2
,
"helloworld"
).
runHead
_
<-
LogUtils
.
debug
(
s
"${
cache1.toString} ${cache2.toString}
"
)
_
<-
putStrLn
(
"Hello good to meet you!"
)
}
yield
()).
foldM
(
e
=>
LogUtils
.
debug
(
s
"error => $e"
).
exitCode
,
...
...
examples/scala2-12/src/main/scala/org/bitlap/tools/CacheValue.scala
0 → 100644
浏览文件 @
0b1b7010
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
]
}
cacheable-caffeine/src/test/scala/org/bitlap/cacheable/caffeine/UseCas
eExample.scala
→
examples/scala2-13/src/main/scala/org/bitlap/tools/Cach
eExample.scala
浏览文件 @
0b1b7010
...
...
@@ -19,15 +19,15 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package
org.bitlap.
cacheable.caffeine
package
org.bitlap.
tools
import
org.bitlap.cacheable.caffeine.Implicits._
import
scala.util.Random
import
org.bitlap.cacheable.core.
{
Cache
,
LogUtils
}
import
org.bitlap.cacheable.caffeine.Implicits._
import
zio.console.putStrLn
import
zio.stream.ZStream
import
zio.
{
ExitCode
,
UIO
,
URIO
,
ZIO
}
import
scala.util.Random
import
org.bitlap.cacheable.core.cacheable
/**
* use these function to test it.
...
...
@@ -35,8 +35,9 @@ import scala.util.Random
* @author 梦境迷离
* @version 1.0,2022/3/18
*/
object
UseCas
eExample
extends
zio
.
App
{
object
Cach
eExample
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
))
...
...
@@ -47,36 +48,21 @@ object UseCaseExample extends zio.App {
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readStreamFunction"
),
List
(
id
,
key
))
}
def
readFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
String
]
=
{
val
$result
=
ZIO
.
effect
(
"hello world"
+
Random
.
nextInt
())
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readFunction"
),
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"
))
}
def
updateFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
String
]
=
{
val
$result
=
ZIO
.
effect
(
"hello world"
+
Random
.
nextInt
())
Cache
.
evict
(
$result
)(
List
(
"readFunction1"
,
"readFunction2"
))
}
def
readEntityFunction
(
id
:
Int
,
key
:
String
)
:
ZIO
[
Any
,
Throwable
,
CacheValue
]
=
{
val
$result
=
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
))
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readEntityFunction"
),
List
(
id
,
key
))
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
]
=
{
val
$result
=
ZStream
.
fromEffect
(
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
)))
Cache
(
$result
)(
List
(
"UseCaseExample"
,
"readStreamEntityFunction"
),
List
(
id
,
key
))
ZStream
.
fromEffect
(
ZIO
.
effect
(
CacheValue
(
Random
.
nextInt
()
+
""
)))
}
override
def
run
(
args
:
List
[
String
])
:
URIO
[
zio.ZEnv
,
ExitCode
]
=
(
for
{
ret
<-
readStreamEntityFunction
(
1
,
"hello-world"
).
runHead
cache
=
zio
.
Runtime
.
default
.
unsafeRun
(
ZCaffeine
.
hGet
[
CacheValue
](
"UseCaseExample-readStreamEntityFunction"
,
"1-hello-world"
))
_
<-
LogUtils
.
debug
(
s
"${
ret.toString} $cache
"
)
cache1
<-
readStreamEntityFunction
(
1
,
"hello-world"
).
runHead
cache
2
<-
updateStreamFunction
(
2
,
"helloworld"
).
runHead
_
<-
LogUtils
.
debug
(
s
"${
cache1.toString} ${cache2.toString}
"
)
_
<-
putStrLn
(
"Hello good to meet you!"
)
}
yield
()).
foldM
(
e
=>
LogUtils
.
debug
(
s
"error => $e"
).
exitCode
,
...
...
examples/scala2-13/src/main/scala/org/bitlap/tools/CacheValue.scala
0 → 100644
浏览文件 @
0b1b7010
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
]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录