Created
September 9, 2011 19:12
-
-
Save davidfowl/1207068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Global : System.Web.HttpApplication { | |
protected void Application_Start(object sender, EventArgs e) { | |
var store = new SmartMessageStore(); | |
DependencyResolver.Register(typeof(IMessageStore), () => store); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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