Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Updated IPrefetchable implementation utilizing AACache
internal sealed class AAInventoryItemCache : IPrefetchable
{
private Dictionary<int, InventoryItem> _InventoryItems = new Dictionary<int, InventoryItem>();
public void Prefetch()
{
_InventoryItems.Clear();
foreach (InventoryItem item in AACache<InventoryItem>.SelectRecords())
{
_InventoryItems[item.InventoryID.Value] = item;
}
}
private Dictionary<int, InventoryItem> InventoryItems
{
get
{
return _InventoryItems;
}
}
public static InventoryItem GetInventoryItem(int inventoryID)
{
AAInventoryItemCache cache = GetSlot();
cache.InventoryItems.TryGetValue(inventoryID, out InventoryItem item);
return item;
}
public static AAInventoryItemCache GetSlot()
{
return PXDatabase.GetSlot<AAInventoryItemCache>(typeof(AAInventoryItemCache).FullName, typeof(InventoryItem));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment