using same Element instance in multiple cache

View: New views
4 Messages — Rating Filter:   Alert me  

using same Element instance in multiple cache

by Tim Eck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

This question might be a bit silly or pedantic, but is it strictly wrong to put() the same Element instance in more than one cache? The element instance itself doesn’t look like it has a back reference to the containing cache, so that aspect seems okay.

 

Anyway, just wondering if anyone has thoughts on this? Apologies if I’ve missed a prior post/FAQ/javadoc/etc on this – I did search.

 

thanks

-tim


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list

Re: using same Element instance in multiple cache

by snekse :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's been awhile since I've looked at the API, but I would think the stats would be effected.  This could effect how the element ages out of each cache.

On Tue, May 20, 2008 at 4:12 PM, Tim Eck <teck@...> wrote:

This question might be a bit silly or pedantic, but is it strictly wrong to put() the same Element instance in more than one cache? The element instance itself doesn't look like it has a back reference to the containing cache, so that aspect seems okay.

 

Anyway, just wondering if anyone has thoughts on this? Apologies if I've missed a prior post/FAQ/javadoc/etc on this – I did search.

 

thanks

-tim


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list

Re: using same Element instance in multiple cache

by gregluck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tim

No it is not incorrect. There are no back references. 

If you put an Element in a Cache, it means the Cache holds a reference to it, or if it is serialzed to disk, a file pointer.

When you retrieve an element from a cache, most of the time you will have a local variable or something else which will hold a reference to it, until it goes out of scope. That is normal operation. 

To remove an Element from a Cache with in an MemoryStore really means to remove the reference. The Element continues to exist until it gets Garbage collected. If it is in another Cache, then it will not be and you can still use it. 

The only real complication comes with DiskStore. Once an Element gets Serialized and then you get it and it gets Deseriazilzed it will be a different Object graph to the one you are holding onto in the other Cache. As long as you realise this, no problem.


On 21/05/2008, at 7:12 AM, Tim Eck wrote:

This question might be a bit silly or pedantic, but is it strictly wrong to put() the same Element instance in more than one cache? The element instance itself doesn’t look like it has a back reference to the containing cache, so that aspect seems okay.
 
Anyway, just wondering if anyone has thoughts on this? Apologies if I’ve missed a prior post/FAQ/javadoc/etc on this – I did search.
 
thanks
-tim
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list

Regards


Greg Luck


skype: gregrluck
yahoo: gregrluck
mobile: +61 408 061 622




-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list

Parent Message unknown Re: using same Element instance in multiple cache

by gregluck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quite rare I would say. The other thing I sometimes see is the same value put in multiple Elements with different keys, so as to support multikeys.

On 21/05/2008, at 8:34 AM, Tim Eck wrote:

Thanks Greg! To give you a little context to this question….I think someone here at Terracotta made a bad assumption that Elements wouldn’t be used in more than one Cache (we inject a back reference to the cache which simply isn’t a valid thing to do). I’ll see that it is resolved.
 
Any idea how common this type of usage is in the wild (ie. using the same Element in more than one cache)?
 
-tim
 
 

From: Greg Luck [gluck@...] 
Sent: Tuesday, May 20, 2008 3:26 PM
To: Tim Eck
Cc: ehcache-list@...
Subject: Re: [ehcache-list] using same Element instance in multiple cache
 
Tim
 
No it is not incorrect. There are no back references. 
 
If you put an Element in a Cache, it means the Cache holds a reference to it, or if it is serialzed to disk, a file pointer.
 
When you retrieve an element from a cache, most of the time you will have a local variable or something else which will hold a reference to it, until it goes out of scope. That is normal operation. 
 
To remove an Element from a Cache with in an MemoryStore really means to remove the reference. The Element continues to exist until it gets Garbage collected. If it is in another Cache, then it will not be and you can still use it. 
 
The only real complication comes with DiskStore. Once an Element gets Serialized and then you get it and it gets Deseriazilzed it will be a different Object graph to the one you are holding onto in the other Cache. As long as you realise this, no problem.
 
 
On 21/05/2008, at 7:12 AM, Tim Eck wrote:


This question might be a bit silly or pedantic, but is it strictly wrong to put() the same Element instance in more than one cache? The element instance itself doesn’t look like it has a back reference to the containing cache, so that aspect seems okay.
 
Anyway, just wondering if anyone has thoughts on this? Apologies if I’ve missed a prior post/FAQ/javadoc/etc on this – I did search.
 
thanks
-tim
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list
 
Regards
 
Greg Luck
 
skype: gregrluck
yahoo: gregrluck
mobile: +61 408 061 622
 


 

Regards


Greg Luck


skype: gregrluck
yahoo: gregrluck
mobile: +61 408 061 622




-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ehcache-list mailing list
ehcache-list@...
https://lists.sourceforge.net/lists/listinfo/ehcache-list
LightInTheBox - Buy quality products at wholesale price