Search code examples
ormcoldfusionehcachecoldfusion-9

How to cache rarely changed many-to-one entity in CF ORM?


How to cache rarely changed many-to-one entity in CF ORM, such as, userType where there are only < 10 types? I don't want the extra select to get the type name.

EhCache? Any XML needed to be config first? Any thing I need to add in the many-to-one cfproperty?

Thank you.


Solution

  • If UserType is a component, you specify cacheuse="read-only" cachename="UserType" in the component definition. read-only is the fastest and is good for cases such as the one you describe.

    In my experience, simply specifying the cache value on the property in the owning component did not cause the caching that you'd expect... I needed to specify it directly on the component-being-cached

    Because you're using read-only for speed, you'll need something somewhere to let you evict that cache when data are updated:

    ormEvictEntity("UserType");