Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] trying to write a simple caching aspect

Not sure how to do something like this with AspectJ, but it raised a red flag for me:
 
I wouldn't try to do something like this with a constructor -- that would severely change the semantics of "new", which the caller expects to always return a new instance of something.
 
If you had some factory methods that you added caching to, this would be fine (again, depending on the semantics of the methods), but be careful how things are documented. If the factory method guarantees a new object (which is what "new" does), you shouldn't change the semantics like this, as the caller code may have been written to rely on this behavior.
 
(This is one of the things that scares me about AspectJ...)
-- Scott


From: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Jody Brownell
Sent: Thursday, October 21, 2004 11:18 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] trying to write a simple caching aspect

Hi – I am new to aspectj, I am working through some example and trying to develop a few aspects as a proof of concept.

The first aspect I am trying to develop is a real simple caching aspect which caches objects based on the implementation of a tag interface.

 

What I would like to do is when a constructor is called, check if the class implements an interface, if it does check the cache. If there is

no reference in the cache, proceed, cache the object and then return it. Otherwise return the cached instance.

 

What I need to be able to do is get the name of the class the constructor is being called on. My pointcut should really select all

constructors in the system (maybe confined to a package) with any number of arguments. Once I have the class object or the name,

I can determine if the cache should be consulted.

 

Is this possible? If so could someone provide me with an example of the pointcut and advice.  I would provide what I have already but I

am stumped as to how I can capture class of the object I am trying to instantiate. My problem is I would like to capture the class as context in

an around advice using a target() like construct.

 

 

Thanks in advance.

Jody b.

 

 


Back to the top