hi,
I've had several occations where I was using the sysGlobalCache method for caching purposes.
Great class for caching or - combined with the info and application classes - exposing info throughout the whole application. Only ... the owner needs to be a string and once a value is added; all other values for that owner have to be of the same type. Sometimes I want to use an int as owner or store different types with the same owner.
So this would not be possible:
myGlobalCache.set('myowner', 'key1', 'value_x');
myGlobalCache.set('myowner', 'key2', 1234);
because 'value_x' is a string and 1234 is an integer value.
Same story for the code below:
myGlobalCache.set(myClass, 'key2', 'value_y');
Because the owner (myClass) in this case is not a string, but a custom class.
That's why I created an extended version of the sysGlobalCache object that can accepts different types for the values with the same owner and takes an optional parameter (default Types::String) for the owner type.
Haven't benchmarked it but I'd expect a slight performance penalty because of some extra logic.
You could even take it a step further and replace the sysGlobalCache in the info and/or application classes.
XPO containing the class can be downloaded here.
Enjoy!
No comments:
Post a Comment