Loading ...

Simplest Caching Explanation

today I want to give one more explanation of how to use caching and slots for caching purposes. Also there are plenty of articles on the subject,  I want to give one more with simplest recipe. So, if you need to cache something, you'll need to follow this procedure:

  1. declare you class as something that inherits IPrefetchable
  2. Create some placeholder in your class for storing items in the cache
  3. Implement Prefetch
  4. Implement GetSlot

 

Take a look on the code below, how it can be done:

public class ArTranFetcher : IPrefetchable
{
	private List<ARTran> _arTranList = new List<ARTran>();
 
	public void Prefetch()
	{
		_configurableList = new List<ARTran>();
 
		var dbRecords = PXDatabase.Select<ARTran>();
		foreach (var csAttributeDetailConfigurable in dbRecords)
		{
			_arTranList.Add(csAttributeDetailConfigurable);
		}
	}
 
	public static List<ARTran> GetARTrans()
	{
		var def = GetSlot();
		return def._arTranList;
	}
		
	private static ArTranFetcher GetSlot()
	{
		return PXDatabase.GetSlot<ArTranFetcher>("ARtranFetcherSlot"typeof(ARTran));
	}
 
}

 

few more explanations on presented code.

  1. Placeholder will be _arTranList 
  2. GetSlot will be monitoring database ARTran ( because of typeof(ARTran) statement ). So each time ARTRan will be updated, GetSlot will be executed automatically via framework.
  3. In your code you can get cached valus via following line of code: var arTrans = ArTranFetcher.GetARTrans();

 

with usage of such tricks, you can optimize plenty of staff. The only warning would be don't cache ARTran, as it will swallow up all memory of your server.

Need custom solutions tailored to your needs?

If you’re looking to optimize your Acumatica development with advanced caching techniques like the one described in this article, but need a more tailored approach, we’re here to help! Whether you’re looking to improve performance, streamline processes, or implement complex customizations, we can create a solution that fits your specific requirements.

Request a customization today! Drop us a message, and let’s discuss how we can help optimize your Acumatica experience.

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5