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

Gotcha -- I glossed over your mention of a tag interface. I'm cool with that ;)
 
-- Scott


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

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.

 

JB> That is what the tag interface is for (ITransparentSessionCache) – the developer MUST subscribe explicitly to this caching functionality.

if we force the use of factories – we would have to develop a significant amount of code just to use aspectj.

 

I seen the factory example in the aspectj in action (excellent book BTW!!!!)... I am trying to avoid that if I can – I need something a little more

seamless... at least until we are through the prototyping/POC stages. Caching on construction would be a HUGE bonus for us.

 

I do agree with you though it could be quite dangerous.... but extremely elegant at the same time... IMO.

 

 

 

 

 

-----Original Message-----
From: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Scott Stanchfield
Sent: Thursday, October 21, 2004 12:29 PM
To: aspectj-users@xxxxxxxxxxx
Subject: 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