Caching with ehcache-spring-annotations API
This blog contains a simple example of spring ehcache. This cache is use to save static data in form of Object. This example has two components, service and model; here service contains basic curd operations, along with a cache operation.
Request 1
[AccountDataServiceTest] => [AccountDataService] => [AccountDataServiceImpl] => [EhcacheInterCepter] => [CachedAccountData]
Request 2
[AccountDataServiceTest] => [AccountDataService] => [EhcacheInterCepter] => [CachedAccountData]
First request call actual service to retrieve data from AccountDataService and store it to cached via EhcacheInterCepter.
Second request call EhcacheInterCepter to retrieve cached data from EhcacheInterCepter. Actual AccountDataService will call after given interval.
To simulate this poc, please checkout code from url (http://code.google.com/p/wikipoc/source/browse/trunk/spring-ehcache/)
Project Structure
| |
spring-ehcach
| |
Main Package
| |
AccountDTO
|
Account DTO with basic account information like accountId, accountHolderName, accountEmail, accountContactNo, accountDOB, currency
|
AccountListDTO
|
List of Account DTO
|
AccountDataService
|
Interface of AccountDataService
|
AccountDataServiceImpl
|
Actual implantation of AccountDataService with curd oprations
|
account-ehcache.xml
|
Ehcache operations descriptor File
|
spring-ehcache-context.xml
|
Spring context descriptor File
|
Test Package
| |
AllTests
|
All Test Cases Starting Point.
|
AccountDataServiceTest
|
Account Data Service Test Case
|
spring-ehcache-test-context.xml
|
Spring context descriptor File for test package.
|
- Create a maven project spring-ehcache
- Add below mention required dependencies in pom.(Pom.xml)
- Prepare AccountDTO, and AccountListDTO.
- Prepare an Interface for Service (AccountDataService).
- Implements of service interface (AccountDataServiceImpl). Prepare cached method cached account Data
- Prepare spring wiring for service classes and configure cache manager with service.
- Configure accountDataService bean an
- Configure cache Manager and refresh interval time, and cache configuration file.
Request 1
[AccountDataServiceTest] => [AccountDataService] => [AccountDataServiceImpl] => [EhcacheInterCepter] => [CachedAccountData]
Request 2
[AccountDataServiceTest] => [AccountDataService] => [EhcacheInterCepter] => [CachedAccountData]
First request call actual service to retrieve data from AccountDataService and store it to cached via EhcacheInterCepter.
Second request call EhcacheInterCepter to retrieve cached data from EhcacheInterCepter. Actual AccountDataService will call after given interval.
To simulate this poc, please checkout code from url (http://code.google.com/p/wikipoc/source/browse/trunk/spring-ehcache/)
Comments
Post a Comment