Skip to content

Commit 2b30d11

Browse files
Update cache.md
1 parent 935365a commit 2b30d11

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

docs/lab/smt/cache.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,20 @@ val data = Map(
3232
```scala
3333
object CacheImplicits {
3434

35-
implicit lazy val testEntityCache: GenericCache.Aux[String, TestEntity] = // String:缓存key,TestEntity:缓存值
36-
GenericCache[String, TestEntity](CacheType.Lru()) // 缓存类型 lru
37-
38-
// implicit lazy val testEntityAsyncCache: GenericCache.Aux[String, TestEntity] = // String:缓存key,TestEntity:缓存值
39-
// GenericCache[String, TestEntity](CacheType.Lru(), ExecutionContext.Implicits.global) // Future cache
35+
implicit lazy val testEntityAsyncCache: GenericCache.Aux[String, TestEntity] = // String:缓存key,TestEntity:缓存值
36+
GenericCache[String, TestEntity](CacheType.Lru(), ExecutionContext.Implicits.global) // Future cache
4037
}
4138
```
4239

4340
2. 初始化-获取缓存
4441
```scala
4542
import CacheImplicits._
4643

47-
val cache: CacheRef[String, TestEntity, Identity] = Cache.getSyncCache[TestEntity]
48-
// Future
49-
// val asyncCache: CacheRef[String, TestEntity, Future] = Cache.getAsyncCache[TestEntity]
44+
val asyncCache = Cache[String, TestEntity]
5045
cache.init(data)
5146
```
5247

5348
3. 从缓存中取数据
5449
```scala
55-
val result: Option[TestEntity] = cache.getT("etc") // 特殊key需要传CacheKeyBuilder
56-
```
57-
58-
4. 从缓存中只取数据的一个`key`字段
59-
```scala
60-
val keyOpt: Option[String] = cache.getTField("etc", CaseClassField[TestEntity](_.key))
50+
val result: Future[Option[TestEntity]] = cache.getT("etc") // 特殊key需要传CacheKeyBuilder
6151
```

0 commit comments

Comments
 (0)