项目作者: tigrulya-exe

项目描述 :
JVM library for server-side HTTP-cache validation boosting
高级语言: Kotlin
项目地址: git://github.com/tigrulya-exe/kcache.git
创建时间: 2020-11-15T14:52:35Z
项目社区:https://github.com/tigrulya-exe/kcache

开源协议:

下载


KCache

JVM library for server-side HTTP-cache validation boosting. KCache adds caching layer for ETag HTTP header in Spring Boot powered applications.

Installation



Maven/Gradle import instructions

Usage

Mark request handler method as eligible for ETag caching

  1. @GetMapping("/workers/{workerId}/area")
  2. @KCacheable(
  3. resources = ["workers", "areas"],
  4. // optional
  5. keys = ["#args[0]"],
  6. // optional
  7. resultBuilder = ResponseEntityKCacheResultBuilder::class
  8. )
  9. fun getWorkerAreaById(
  10. @PathVariable workerId: Int
  11. ): ResponseEntity<Area> {
  12. return ResponseEntity.ok(
  13. // business logic
  14. workerService.getWorkerAreaById(workerId)
  15. )
  16. }

Mark method as cacheable resource state mutator

  1. @KCacheEvict(
  2. resources = ["workers"],
  3. // optional
  4. keys = ["#args[0].id"],
  5. )
  6. fun updateWorker(worker: Worker){
  7. workersRepository.update(worker)
  8. }

Configure framework

Framework configuration is available via Spring application.(yaml|properties), e.g.:

  1. kcache:
  2. jpa:
  3. listener:
  4. enable: true
  5. state-storage:
  6. # also supports RAM and redis storages
  7. name: hazelcast
  8. hazelcast:
  9. discovery:
  10. type: TCP_IP
  11. tcp-ip:
  12. members: localhost
  13. redis:
  14. host: localhost
  15. port: 6379
  16. aop:
  17. # also supports AspectJ
  18. type: spring-aop