[Cachebox] My strings are turning into numbers after caching

Sorry I don’t know what version of CacheBox we’re using (how can I tell? I dug into the source code a little but didn’t see anything).

We recently enabled caching in our application using CacheBox and CouchBase. I am having issues where my string data is turning into numbers. For example I have a query like

select tcode, name FROM transportationZones

both code and name are varchar fields. The tcode values look like ‘0000000001’ or ‘0000000015’. This later gets used in some ajax call like:
routes.cfc?method=getRoute&tzone=0000000001

This works the first time my page is run, but on subsequent tests I get no data back from routes.cfc. I tracked it down to caching. After the transportation zones get cached my ajax call looks like this:
routes.cfc?method=getRoute&tzone=1

so it fails with no match. Where is the JSON conversion happening, it’s in CacheBox, before it gets sent to CouchBase, right? So somewhere I should be able to modify it to use getMetaData and determine the types before converting to JSON? Or even better just use a JSON converter that will pay attention to the datatypes and encode the JSON properly?

False alarm. I think my leading zeroes are getting stripped somewhere else. Sorry.

Ok, the problem happens when I run my data through a JSON serializer (to inject the data into the page so JavaScript can use it). When the data is not cached it works fine. When the data is cached, even though the data from the cache looks correct (0000000001) the serializer drops the leading zeroes. It’s because there is no meta data on the data returned from the cache.

How can we fix this? Ideally the cached data would look exactly like the uncached data.

treat it as a string.

put a space in the front.

The CacheBox version is stored in the CacheFactory.cfc file. Alternatively, you can call CacheBox.getVersion().

That sounds like a common issue innate to ColdFusion’s JSON serialization in early versions. As a quick work around, append a string to the beginning of the data, and take it off later.

Alternatively, you could modify the Provider and replace any instances of serializeJSON and deserializeJSON with a custom library. I’m pretty sure this issue lies in how CF is treating the JSON and unrelated to Couchbase or CacheBox or the CacheBox Couchbase Provider.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Excellent, thanks for your help.