Application-wide Caching in Acumatica with Slots and IPrefetchable
I’m doing a guest post this week for my awesome friends at the Acumatica Developer Network on a technique that I covered during my session at the last Virtual Developer Conference and is not widely used by developers outside the Acumatica development team — slots and the IPrefetchable interface.
When monitoring and profiling any database-driven application, you often see the same queries and the same data accessed over and over again by different modules and users of your application. The performance hit of these queries may not be evident at first, especially if they’re simple. However, as the number of users and the complexity of your application increases, the effects compound and ultimately result in noticeable overhead.
What if you could load this data once, cache it, and make it available to every session? The Acumatica framework provides a mechanism to do this called “slots”. Acumatica provides a special interface, IPrefetchable, that enables lazy-loading of your data the first time that it’s needed and takes take care of invalidating your cache, if and when the cached data gets modified elsewhere in the application.
Internally, slots are used for many scenarios. Examples of structures that are cached in slots include:
- Access Rights
- Site Maps
- Segmented Key Configurations
- AR/AP Discount Rules