Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created June 20, 2021 13:37
Show Gist options
  • Save rdelrosario/fa60efd4a70d67ff52ade4c2ed3fbb1a to your computer and use it in GitHub Desktop.
Save rdelrosario/fa60efd4a70d67ff52ade4c2ed3fbb1a to your computer and use it in GitHub Desktop.
public class ItemManager : IItemManager
{
public ItemManager()
{
ItemChanges = _itemsCache.Connect()
.RefCount();
}
public Optional<Item> Get(string id) => _itemsCache.Lookup(id);
public IObservable<IChangeSet<Item, string>> ItemChanges { get; }
public void AddOrUpdate(Item item) => _itemsCache.AddOrUpdate(item);
public void Remove(Item item) => _itemsCache.Remove(item);
private SourceCache<Item, string> _itemsCache = new SourceCache<Item, string>(item => item.Id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment