Add support for caching

#4 · closed · 1 comments

View on GitHub ↗

CaptainCodeman

The option to cache embedly responses would help avoid going over the account usage limit and incurring additional fees. The caching should be configurable to either obey the cache_age value in the response (default) or allow some arbitrary cache duration.

Comments

CaptainCodeman

Initial implementation committed. Caches individual responses for each requested Url, not the entire response for a batch of Urls. If a Url is re-requested then it can be served from the cache rather than going over the wire to embedly. Cache key is a Guid based on the MD5 hash of the Url. `NullResponseCache` effectively disables caching and is the default if an `IResponseCache` is not passed into the `Client` constructor. A simple dictionary based `InMemoryResponseCache` is also included in the assembly and an `AdoResponseCache` in the sample project along with a script to setup the table for SQL Server. Caching makes use of [Reactive Extensions / Rx](http://msdn.microsoft.com/en-us/data/gg577609) to split the stream of requested Urls and serve some from the cache and the rest from embedly. This code may change as I learn more about using Rx correctly but it seems to produce the desired effect.