General question: If I wanted to cache objects in ...
# cfml-general
r
General question: If I wanted to cache objects in the application scope, and return them as an array, is it better to store them as a struct (keyed by object ID) for fast subset retrieval? Or is it better to store the cache as an array for faster return of all objects? I guess the answer depends on which retrieval operation (all vs some) performed more often?
z
the answer to any performance question is to profile the different approaches, but generally speaking I wouldn't even worry about this, unless you have a very large amount of data, but even then structs are pretty fast
d
Really depends on your storage and retrieval patterns, but I agree that unless you have a huge amount of data and/or a ton of puts or gets, anything you do will be fast enough not to matter, That said, caching a query gives you tons of easily understood filtering possibilities for getting the data back out. But for example, if you always want just these 3 subsets, you could cache a struct containing those 3 arrays.
r
Thanks for the input. I only have about 1000 objects to cache, but they're huge and get requested very often. I ended up caching the json of these objects in a struct since they're always returned as json, and normally just a subset is requested. It takes a lot of load off ram and cpu not having to SerializeJSON() what comes out to be about 150kb of json per object.