This runs a cache client that connects to a cache server running locally or to a manged service in PCF through service binding. This implementation is based on look aside cache that is been abstracted using spring caching aspect.
As always with spring-boot, a simple annotation would get you started. Annotate the Configuration class with
@ClientCacheApplication
to get started with client cache configuration. Along with the following annotations,
@Configuration
@EnableEntityDefinedRegions(basePackages = { "io.pivotal.pccclient.region" })
@EnableGemfireRepositories(basePackages = { "io.pivotal.pccclient.repository" })
@EnableLogging(logLevel = "info")
@EnableCaching(proxyTargetClass = true)
@ClientCacheApplication()
@EnablePdx
-
@ClientCacheApplication
marks it to be a gemfire/geode cache client -
@EnableEntityDefinedRegions
marks spring application to enable the creation of gemfire/geodeRegions
based on the application persistent entities -
@EnableGemfireRepositories
marks spring application to enable gemfire/geode repos -
@EnableCaching
is the spring abstraction for cache management
If the default needs to be changed, let’s say connection parameters, it can be down with params
@ClientCacheApplication(maxConnections = 100, minConnections = 10)
In a similar way, other options can be modified/tweaked accordingly either through annotations or through spring.data.gemfire.* properties
Define a region entity by annotating the domain object with @Region
annotation
@Region("formula1region")
public class Car implements Serializable {
...
}
formula1region
is important as it is name being used in the cache server to create a gemfire region.
Define a repository to act on the region entity
@Repository
interface CarRepository extends CrudRepository<Car, String> {
...
}
With spring data jpa API, data can be stored and retrieved. This uses a persistence store as well. Data by default will be persisted in a datastore.
Use spring caching annotation to put the data to the cache server @Cacheable(value = "cars")
.
This is based on look aside pattern. When there is a cache miss, data will be put into the server automatically by spring caching abstraction. On subsequent calls, data will be served from the cache layer.