Caching application entities based on an aspect-oriented approach
-
Upload
sidcley-soares -
Category
Technology
-
view
384 -
download
1
Transcript of Caching application entities based on an aspect-oriented approach
![Page 1: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/1.jpg)
Caching application entities
based on an aspect-oriented
approach
Sidcley Soares
![Page 2: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/2.jpg)
Motivation
• This work will present an approach to accomplishalmost transparent caching in a web application usingaspects to acheive caching based on the Observerpattern.
• Caching can be seen as a cross-cutting concern and itsimplementation based on aspects can bring severalbenefits when compared to industry standards.
![Page 3: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/3.jpg)
Problem
• Industry standard way of caching:
– Non-centralized code;
– Complex refresh strategy;
– Hard to maintain;
– Error-prone;
![Page 4: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/4.jpg)
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.
![Page 5: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/5.jpg)
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.
![Page 6: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/6.jpg)
Caching Annotations
CacheableSets 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.
EvictWhenever 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.
![Page 7: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/7.jpg)
CachingAspect
Handling @CacheableAn 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.
![Page 8: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/8.jpg)
CachingAspect
Handling @EvictAn 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.
![Page 9: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/9.jpg)
Caching mechanism
Default implementation uses a ConcurrentHashMap but an interface will be created so clients can implement their own Caching provider.
![Page 10: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/10.jpg)
Cache interface
![Page 11: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/11.jpg)
Cacheable annotation
![Page 12: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/12.jpg)
CacheImpl (default)
![Page 13: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/13.jpg)
CacheAspect
![Page 14: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/14.jpg)
CacheAspect
![Page 15: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/15.jpg)
CacheAspect
![Page 16: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/16.jpg)
CachingConfiguration
![Page 17: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/17.jpg)
CachingObserver
![Page 18: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/18.jpg)
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 tobe 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)
![Page 19: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/19.jpg)
Evict
![Page 20: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/20.jpg)
ObserverFactory
![Page 21: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/21.jpg)
Conclusion
• This work presented a solution to address caching in java applications usingannotations and aspects.
• This worked aimed to create a solution where is not required to put too mucheffort in order to enable caching on the application.
• It is also noticeable that by using aspects the work involved on maintenance orimprovements is highly reduced.
![Page 22: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/22.jpg)
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.
![Page 23: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/23.jpg)
Future work
• This work does not cover the strategy of caching. It basically assumes thatall requests to a given method can be cached. Future work may addressmore techniques on caching based existent techiniques but still havingthe 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 theproposed solution. Even though, the proposed solution seems to improvethe performance of Java applications a test covering such aspects was notperformed due to deadline constraints.
![Page 24: Caching application entities based on an aspect-oriented approach](https://reader035.fdocuments.in/reader035/viewer/2022062419/55a2d7871a28ab887d8b456f/html5/thumbnails/24.jpg)
References
AspectJ in Action: Enterprise AOP with Spring Applications 2nd edition (2009)
Effective Java 2nd edition (2008)
Spring in Practice 1st edition (2013)