Hi folks,
I’ve been digging into the ColdBox caching features lately and wanted to see if I’m on the right track for my approach. I am referencing: http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbCachingGuide
The app i’m building is a REST API. The apps which consume the API periodically poll a handful of endpoints to refresh their data - i.e getUser (returns JSON user object), getLocations (returns JSON locations list). For the most part the data returned from these enpoints doesn’t change that often. The only one that would be most likely to change is the UserObject.
For the getUser request my handler makes a request to UserService, which loads the data through ORM then returns back a struct. My postHandler then converts and returns the data using event.renderData.
I’m thinking about implementing caching in my userService to first check the cache to see if the cached object exists…if it does return it, else load the data via ORM, then cache it.
//user service
function getUser(userid){
var oMD = structnew();
var user = 'user_' & arguments.userid;
if ( getColdboxOCM().lookup(user) ){
oMD = getColdboxOCM().get(user);
}else{
var getUser = EntityLoadByPK('User',arguments.userid);
///create struct
var userStruct = {}, etc...
//place struct into cache
getColdboxOCM().set(user,userStruct);
}
}
This my first time working with ColdboxOCM. Is the above a valid approach for using this feature and caching on a user by user basis? Obviously I would need to build in a feature on say a userUpdate endpoint which would do the same lookup, expire the key, and the reset after update.
Thanks all.
Nolan