Skip to content

JVM library for server-side HTTP-cache validation boosting

Notifications You must be signed in to change notification settings

tigrulya-exe/kcache

Repository files navigation

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

@GetMapping("/workers/{workerId}/area")
@KCacheable(
    resources = ["workers", "areas"],
    // optional
    keys = ["#args[0]"], 
    // optional
    resultBuilder = ResponseEntityKCacheResultBuilder::class 
)
fun getWorkerAreaById(
    @PathVariable workerId: Int
): ResponseEntity<Area> {
    return ResponseEntity.ok(
        // business logic
        workerService.getWorkerAreaById(workerId)
    )
}

Mark method as cacheable resource state mutator

@KCacheEvict(
    resources = ["workers"],
    // optional
    keys = ["#args[0].id"], 
)
fun updateWorker(worker: Worker){
    workersRepository.update(worker)
}

Configure framework

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

kcache:
  jpa:
    listener:
      enable: true
  state-storage:
    # also supports RAM and redis storages    
    name: hazelcast
    hazelcast:
      discovery:
        type: TCP_IP
        tcp-ip:
          members: localhost
    redis:
      host: localhost
      port: 6379
  aop:
    # also supports AspectJ
    type: spring-aop