Caching didn't seem to be working ...

Topics: Developer Forum, User Forum
Mar 26, 2009 at 11:09 PM
In Flickr.net, around line 626, the code to cache responses appears to use Cache.Responses.Get () with the full URL of the request (url + "?" + variables) but when it creates the ResponseCacheItem lower down  it was using just the url to remember the response.  I changed my copy as follows and now it actually caches responses.  Am I missing something or was there a bug here?


                string urlComplete = url + "?" + variables;

                ResponseCacheItem cached = (ResponseCacheItem) Cache.Responses.Get(urlComplete, cacheTimeout, true);
                if (cached != null)
                {
                    log.DebugFormat("Cache hit {0}", urlComplete);
                    _lastResponse = cached.Response;
                    response = Utils.Deserialize(cached.Response);
                }
                else
                {
                    log.DebugFormat("Cache miss {0} timeout was {1}", urlComplete, cacheTimeout);
                    string responseXml = DoGetResponse(url, variables);
                    _lastResponse = responseXml;

                    ResponseCacheItem resCache = new ResponseCacheItem();
                    resCache.Response = responseXml;
                    resCache.Url = urlComplete;
                    resCache.CreationTime = DateTime.UtcNow;

                    response = Utils.Deserialize(responseXml);

                    if( response.Status == ResponseStatus.OK )
                    {
                        Cache.Responses.Shrink(Math.Max(0, Cache.CacheSizeLimit - responseXml.Length));
                        Cache.Responses[resCache.Url] = resCache;
                    }
Coordinator
Mar 27, 2009 at 6:41 PM
Looks good, I've updated the source code with your code.

Sam
Mar 27, 2009 at 7:49 PM
Great and thanks for the quick response!