Caching application entities
based on an aspect-oriented
approach
Sidcley Soares
Motivation
• This work will present an approach to accomplish
almost transparent caching in a web application using
aspect...
Problem
• Industry standard way of caching:
– Non-centralized code;
– Complex refresh strategy;
– Hard to maintain;
– Erro...
Caching Benefits
 Reduce network bandwith usage;
 Reduce load on the producer server;

 Reduce user-perceived delays;
...
Designed solution
•
•
•
•

Solution developed using Java technology;
AspectJ covering APO concerns;
Spring framework for I...
Caching Annotations
Cacheable
Sets the method as a cacheable method. All inputs are taken as
keys and whenever there is a ...
CachingAspect
Handling @Cacheable
An Aspect was created to intercept call to any method which implements
the annotation Ca...
CachingAspect
Handling @Evict
An Aspect was created to intercept call to any method which implements
the annotation Evict....
Caching mechanism
Default implementation uses a ConcurrentHashMap but an interface will be
created so clients can implemen...
Cache interface
Cacheable annotation
CacheImpl (default)
CacheAspect
CacheAspect
CacheAspect
CachingConfiguration
CachingObserver
CompoundKey
Abstract class which can be used to represent a key for cacheable.
In scenarios where you have the same key bu...
Evict
ObserverFactory
Conclusion
• This work presented a solution to address caching in java applications using
annotations and aspects.
• This ...
Conclusion
Framework has been created based on the proposed solution.It can be
found at:
https://github.com/sidcley/cachin...
Future work
• This work does not cover the strategy of caching. It basically assumes that
all requests to a given method c...
References
AspectJ in Action: Enterprise AOP with Spring Applications 2nd edition (2009)
Effective Java 2nd edition (2008)...
Upcoming SlideShare
Loading in …5
×

Caching application entities based on an aspect-oriented approach

595 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
595
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Caching application entities based on an aspect-oriented approach

  1. 1. Caching application entities based on an aspect-oriented approach Sidcley Soares
  2. 2. Motivation • This work will present an approach to accomplish almost transparent caching in a web application using aspects to acheive caching based on the Observer pattern. • Caching can be seen as a cross-cutting concern and its implementation based on aspects can bring several benefits when compared to industry standards.
  3. 3. Problem • Industry standard way of caching: – Non-centralized code; – Complex refresh strategy; – Hard to maintain; – Error-prone;
  4. 4. Caching Benefits  Reduce network bandwith usage;  Reduce load on the producer server;  Reduce user-perceived delays;  Reduce server load for frequently requested content;  Reserve server capacity for non-cacheable content and other operations;  Achieve capital expenditure and operational savings by optimizing server utilization.
  5. 5. Designed solution • • • • Solution developed using Java technology; AspectJ covering APO concerns; Spring framework for Inversion of Control and injecting aspects; Annotations were used in the client for simplicity’s sake and as a flag for clients to represent which parts of contracts they want to cache.
  6. 6. Caching Annotations Cacheable Sets the method as a cacheable method. All inputs are taken as keys and whenever there is a request using the same input the cacheAspect will act and return the cached Object. Evict Whenever there is a request to the method it tells the cache to clean up based on the key. It will clean up and the cached objects associated with the key.
  7. 7. CachingAspect Handling @Cacheable An Aspect was created to intercept call to any method which implements the annotation Cacheable. Whenever there is a call to this annotated method an @around advice will be called implementing the following strategy: 1) get the inputs used to call the annotated method; 2) based on the inputs verify if there is any object already cached; 3) in Case it exists return it to the caller; 4) Otherwhise call the proceed; 5) get the response and Cache it using the cache Mechanism using the input as keys.
  8. 8. CachingAspect Handling @Evict An Aspect was created to intercept call to any method which implements the annotation Evict. Whenever there is a call to this annotated method an @after advice will be called implementing the following strategy: 1) get the inputs used to call the annotated method; 2) based on the inputs verify if there is any object already cached; 3) in Case it exists, it cleans up the cache.
  9. 9. Caching mechanism Default implementation uses a ConcurrentHashMap but an interface will be created so clients can implement their own Caching provider.
  10. 10. Cache interface
  11. 11. Cacheable annotation
  12. 12. CacheImpl (default)
  13. 13. CacheAspect
  14. 14. CacheAspect
  15. 15. CacheAspect
  16. 16. CachingConfiguration
  17. 17. CachingObserver
  18. 18. CompoundKey Abstract class which can be used to represent a key for cacheable. In scenarios where you have the same key but the cache needs to be isolated it is necessary a compound key e.g: Caching all employee per client. In this case compoundKey should implement a logic where it knows the d ifference between client A vs Client B (session awareness Key)
  19. 19. Evict
  20. 20. ObserverFactory
  21. 21. Conclusion • This work presented a solution to address caching in java applications using annotations and aspects. • This worked aimed to create a solution where is not required to put too much effort in order to enable caching on the application. • It is also noticeable that by using aspects the work involved on maintenance or improvements is highly reduced.
  22. 22. Conclusion Framework has been created based on the proposed solution.It can be found at: https://github.com/sidcley/caching It is written in Java and under GPL license so anyone can use and contribute.
  23. 23. Future work • This work does not cover the strategy of caching. It basically assumes that all requests to a given method can be cached. Future work may address more techniques on caching based existent techiniques but still having the advantage of transparent caching through Annotation and Aspects: MRU (Most recently Used) LRU (Least Recently Used) • This work does not address performance/throughput benchmarking of the proposed solution. Even though, the proposed solution seems to improve the performance of Java applications a test covering such aspects was not performed due to deadline constraints.
  24. 24. References AspectJ in Action: Enterprise AOP with Spring Applications 2nd edition (2009) Effective Java 2nd edition (2008) Spring in Practice 1st edition (2013)

×