caching application entities based on an aspect-oriented approach

24
Caching application entities based on an aspect-oriented approach Sidcley Soares

Upload: sidcley-soares

Post on 13-Jul-2015

384 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Caching application entities based on an aspect-oriented approach

Caching application entities

based on an aspect-oriented

approach

Sidcley Soares

Page 2: Caching application entities based on an aspect-oriented approach

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

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

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

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

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

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

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

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

Cache interface

Page 11: Caching application entities based on an aspect-oriented approach

Cacheable annotation

Page 12: Caching application entities based on an aspect-oriented approach

CacheImpl (default)

Page 13: Caching application entities based on an aspect-oriented approach

CacheAspect

Page 14: Caching application entities based on an aspect-oriented approach

CacheAspect

Page 15: Caching application entities based on an aspect-oriented approach

CacheAspect

Page 16: Caching application entities based on an aspect-oriented approach

CachingConfiguration

Page 17: Caching application entities based on an aspect-oriented approach

CachingObserver

Page 18: Caching application entities based on an aspect-oriented approach

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

Evict

Page 20: Caching application entities based on an aspect-oriented approach

ObserverFactory

Page 21: Caching application entities based on an aspect-oriented approach

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

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

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

References

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

Effective Java 2nd edition (2008)

Spring in Practice 1st edition (2013)