tracker issue : CF-3989480

select a category, or use search below
(searches all categories and all time range)
Title:

cacheGet returns values by reference

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/NotABug

Reporter/Name(from Bugbase): Jork Zijlstra / Jork Zijlstra (Jork Zijlstra)

Created: 05/18/2015

Components: Caching

Versions: 11.0

Failure Type: Usability Issue

Found In Build/Fixed In Build: CF11_Final /

Priority/Frequency: Major / All users will encounter

Locale/System: English / Linux Ubuntu 10.10

Vote Count: 0

Problem Description:
Object that are in put in the cache with cachput can be unintentionally edited afterwards when getting it from the cache with cacheget and then update it. 
cacheGet return values by reference, except for simpleValues / arrays (The normal by reference / copy rules seems to apply here).

Steps to Reproduce:
private any function _getCacheTimeSpan()
{
	return createTimeSpan(6, randRange(1,23), randRange(1,59),0);
}

function test()
{
	var cachekey = "test";
	var originalValues = {
		"test" = "test"
	};
		
	cachePut(cachekey & "_" & cachekey, originalValues, _getCacheTimeSpan());
	
	var expectedDuplicate = cacheGet(cachekey & "_" & cachekey);
	
	structUpdate(originalValues, "test", "test2");
	
	writeDump(expectedDuplicate);
}
	
test();


Actual Result:
expectedDuplicate are updated

Expected Result:
expectedDuplicate aren't updated 

Any Workarounds:
- Duplicate it when using cacheget 
- Seralize the object when using cacheput, deserialize when cacheget
- for Query use getShallowCopy after cacheGet, so that iterators won't be shared

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3989480

External Customer Info:
External Company:  
External Customer Name: Jork
External Customer Email:  
External Test Config: My Hardware and Environment details:

Ubuntu 14.04 - CF11,0,05,293506

Attachments:

Comments:

This is actually expected behavior. I previously blogged about it (sorry, my blog is currently offline, so you'll have to read the cached version): https://web.archive.org/web/20120415123407/http://rob.brooks-bilson.com/index.cfm/2010/8/9/Bug-with-Ehcache-and-ColdFusion-Query-Objects
Comment by External U.
7421 | May 19, 2015 11:17:15 AM GMT
I know it is an old issue. We have been using the getshallowcopy method as a fix on the query object for serveral years. It just like you said, every time when using the ehcache you don't expect this behaviour. What I would expect is that the object is saved as a serialized version. When getting it from the cache it is deserialized and this wouldn't be an issue. I have an object on which 4/5 of the properties is the same for each request, the other part is request dependent. So I cache the 4/5 part and after cacheget I add the last part. So for now I serialize for cacheput and desrialize it after cacheget. This method of caching only takes double the time.
Comment by External U.
7422 | May 19, 2015 12:53:21 PM GMT
This is expected behavior, hence closing the bug.
Comment by Akhila K.
7423 | July 08, 2015 04:13:25 AM GMT