Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Created September 9, 2011 19:12
Show Gist options
  • Save davidfowl/1207068 to your computer and use it in GitHub Desktop.
Save davidfowl/1207068 to your computer and use it in GitHub Desktop.
public class Global : System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
var store = new SmartMessageStore();
DependencyResolver.Register(typeof(IMessageStore), () => store);
}
}
public class SmartMessageStore : IMessageStore {
private readonly IMessageStore _store = new InProcessMessageStore();
public Task<IEnumerable<Message>> GetAll(string key) {
return _store.GetAll(key);
}
public Task<IEnumerable<Message>> GetAllSince(string key, long id) {
return GetLastId().ContinueWith(t => {
if (t.Result.HasValue) {
id = Math.Min(id, t.Result.Value - 1);
}
return _store.GetAllSince(key, id);
}).Unwrap();
}
public Task<long?> GetLastId() {
return _store.GetLastId();
}
public Task Save(string key, object value) {
return _store.Save(key, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment