Once you have an extension method, it's a simple matter of using it (don't forget to bring the static class that you defined in the GetOrStore method by adding a usage directive to the namespace containing it, or you wonβt see the GetOrStore<T> extension method) :
IEnumerable<string> addresses = HttpRuntime .Cache .GetOrStore<IEnumerable<string>>( "addresses", () => repository.GetAllAddresses().ToArray() );
Notes:
- We use "addresses" as the cache key, so the result will be saved under this key.
- We call
.ToArray() on an IQueryable<string> to look up addresses and store the results in a cache, not a query.
source share