Skip to content

Instantly share code, notes, and snippets.

@jvanhoesen
Created June 2, 2021 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanhoesen/2306163b9d9efd614058bc47550e4320 to your computer and use it in GitHub Desktop.
Save jvanhoesen/2306163b9d9efd614058bc47550e4320 to your computer and use it in GitHub Desktop.
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