I have a table containing a set of record, which is the available country code. They are used for populating the Web's dropdown list.
It will be common to cache all the available country code. But with the 2 common method to read those code out, they cannot be cached:
1. IList codeList = session.CreateCriteria(typeof(CountryCode)).List();
2. IList codeList = session.Find("from CountryCode");
Either method is using SessionImpl.Find() in the end, which connect to DB and fetch the data from it every time, it cannot read from cache as we all know.
The only way I found is, creating a new table with object class "CodeType", which has children map to the "ChildrenCodeTable". One of the instance map to "CountryCode" table. Everytime I use session.Load() to load the "Parent" CodeType code, which in turn will load all the children, which loaded from the cache after the 1st time loading.
Similar method would be cache all the CountryCode IDs by myself, and use session.Load() to load each of the CountryCode when needed.
These methods seem redundant and complicated (extra table/records or I need to handle my own cache/expire/Evict), but I cannot find any other way.
Please help!
|