Skip to content

Lightgaming/fetch_tray_cache_plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetch_tray_cache_plugin

A fetch_tray plugin to enable hard caching of requests. This plugin is designed to work with servers that don't send cache headers. It is not designed to work with servers that send cache headers.

The plugin is based on the dio_cache_interceptor package with a custom middleware to work with fetch_tray and on the client side (without cache headers).

Usage

Using memory cache

To use the memory cache, simply add the plugin to the FetchTray instance. The memory cache is not persistent and will be cleared when the app is closed.

```dart
import 'package:fetch_tray/fetch_tray.dart';
import 'package:fetch_tray_cache_plugin/fetch_tray_cache_plugin.dart';

void main() {
    FetchTray.init(
        plugins: [
            TrayCachePlugin(
                cacheStoreType: TrayCacheStoreType.memory,
                cacheDuration: const Duration(minutes: 5),
            ),
        ],
    );
}

Using Hive cache

To use a persistent cache, you can use the hive store type. This implementation is based on the dio_cache_interceptor_hive_store package.

You are required to provide a cacheDirectory to store the cache files.

import 'package:fetch_tray/fetch_tray.dart';
import 'package:fetch_tray_cache_plugin/fetch_tray_cache_plugin.dart';

void main() {
    FetchTray.init(
        plugins: [
            TrayCachePlugin(
                cacheStoreType: TrayCacheStoreType.hive,
                cacheDirectory: '/path/to/cache/directory',
            ),
        ],
    );
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 100.0%