예제 #1
0
        private GadgetSpec FetchObjectAndCache(Uri url, bool ignoreCache)
        {
            sRequest request = new sRequest(url)
                        .setIgnoreCache(ignoreCache)
                        .setGadget(url);

            // Since we don't allow any variance in cache time, we should just force the cache time
            // globally. This ensures propagation to shared caches when this is set.
            request.setCacheTtl((int)(refresh / 1000));

            sResponse response = fetcher.fetch(request);
            if (response.getHttpStatusCode() != (int)HttpStatusCode.OK)
            {
                throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
                                          "Unable to retrieve gadget xml. HTTP error " +
                                          response.getHttpStatusCode());
            }

            GadgetSpec spec = new GadgetSpec(url, response.responseString);
            HttpRuntime.Cache.Insert(url.ToString(), spec, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(refresh));
            return spec;
        }
예제 #2
0
        protected MessageBundle fetchBundle(LocaleSpec locale, bool ignoreCache)
        {
            Uri url = locale.getMessages();
            sRequest request = new sRequest(url).setIgnoreCache(ignoreCache);
            // Since we don't allow any variance in cache time, we should just force the cache time
            // globally. This ensures propagation to shared caches when this is set.
            request.setCacheTtl((int)(refresh / 1000));

            sResponse response = fetcher.fetch(request);
            if (response.getHttpStatusCode() != (int)HttpStatusCode.OK)
            {
                throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
                                          "Unable to retrieve message bundle xml. HTTP error " +
                                          response.getHttpStatusCode());
            }

            MessageBundle bundle = new MessageBundle(locale, response.responseString);
            return bundle;
        }