Today i want to share with you a good trick how you can override original PXCache object.
Why you may need it?
- To replace base cache logic, that should not be executed in some cases.
- Forbid cache to read data for database in case of virtual DAC
- Inject required logic to the standard workflow
- Do not clear cache data on graph clearing
- Access protected method
As you may know, that when you (or system) create a new instance of a graph, it will automatically instantiate all caches for each data views that are declared. Unfortunately, because this is unattended process it is almost impossible to adjust it for our own purposes.
But luckily Acumatica is very flexible system and there are several easy ways to do it lately after base initialization. So the reccomended solution will be:
- Create an graph extension for required Graph. Or also you may use constructor of the graph, if you develop new functionality.
- Override Initialize method to add your logic
- Create a new class for cache that should be inherited form PXCache<DAC> type.
- Instantiate a new cache object a new cache of the same DAC type.
- Replace original cache in the PXGraph.Caches collection with a new one.
public class InventoryItemFilterCache : PXCache<InventoryItemFilter>
public InventoryItemFilterCache(PXGraph graph)
public override void Clear()
public override int Persist(PXDBOperation operation)
public class NonStockItemMaintExt : PXGraphExtension<NonStockItemMaint>
public override void Initialize()
Base.Caches[typeof(InventoryItemFilter)] = new InventoryItemFilterCache(Base);
Have a nice Development!