Something like the following should work. Represent the cache as an ISubject and you have an async cache. Internally in the cache you could buffer queries over a time window and batch request them to the server.
Some dummy classes
public struct User
{
public string id;
}
public struct Bid
{
public string userId;
public int bid;
}
The cache object itself
/// <summary>
/// Represent the cache by a subject that get's notified of
/// user requests and produces users. Internally this can
/// be buffered and chunked to the server.
/// </summary>
public static ISubject<string, User> UsersCacheSubject;
Method for dispatching and async queries to the DB
public static Task<User> UsersCache(string id)
{
var r = UsersCacheSubject
.Where(user=>user.id==id)
.Replay(1)
.Take(1);
UsersCacheSubject.OnNext(id);
return r.FirstAsync().ToTask();
}
try it out
public void TryItOut()
{
IObservable<Bid> bidderObservable = Observable.Repeat(new Bid());
var foo = from bidder in bidderObservable
from user in UsersCache(bidder.userId)
where bidder.userId == user.id
select new {bidder, user};
}