caching application entities based on an aspect-oriented approach

Post on 13-Jul-2015

382 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Caching application entities

based on an aspect-oriented

approach

Sidcley Soares

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.

Problem

• Industry standard way of caching:

– Non-centralized code;

– Complex refresh strategy;

– Hard to maintain;

– Error-prone;

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.

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.

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.

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.

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.

Caching mechanism

Default implementation uses a ConcurrentHashMap but an interface will be created so clients can implement their own Caching provider.

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 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)

Evict

ObserverFactory

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.

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.

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.

References

AspectJ in Action: Enterprise AOP with Spring Applications 2nd edition (2009)

Effective Java 2nd edition (2008)

Spring in Practice 1st edition (2013)

top related