Skip to content

pocheshire/Xamarin.CacheHttpHandler

Repository files navigation

Xamarin.CacheHttpHandler

Usage

  1. Install packages CacheHandlerPlugin, CacheHandlerPlugin.Realm, CacheHandlerPlugin.Connectivity

  2. Create handler instance

    var handler = new CacheMessageHandler(
                %your_current_handler_instance%,
                apiCacheService,
                connectionService);

    where

    var apiCacheService = new RealmApiCacheService(new RealmRepository(null));

    or your own IApiCacheService implementation (and you don't need CacheHandlerPlugin.Realm package)

    and

    var connectionService = new ConnectivityService();

    or your own IConnectivityService implementation (and you don't need CacheHandlerPlugin.Connectivity package)

  3. Create HttpClient instance

    var httpClient = new HttpClient(handler);
  4. Register RequestCacheSettings in your own or default ICacheSettingsContainer implementation or add cache settings in request message properties

    var cacheSettingsContainer = new SimpleCacheSettingsContainer();
    
    var requestMessage = new HttpRequestMessage(HttpMethod.Get, %url%);
    
    cacheSettingsContainer.Register(requestMessage, new RequestCacheSettings(600));

    or

    var requestMessage = new HttpRequestMessage(HttpMethod.Get, %url%);
    requestMessage.Properties.Add(CacheMessageHandler.CachedKey, new RequestCacheSettings(600));
  5. ...

  6. PROFIT!

Releases

No releases published

Packages

No packages published

Languages