pub package popularity likes pub points building

shared_preferences-based cache implementation for stateful_service.

Getting started

See the stateful_service package documentation for more information on how to get started.

Once you have a StatefulService, you can use SharedPreferencesStatefulServiceCache to cache the service's state using SharedPreferences.

class UserService extends StatefulService<User> {
  UserService({required super.initialState})
      : super(
    cache: SharedPreferencesStatefulServiceCache(
      key: 'userServiceState',
      encode: (user) => user.name,
      decode: (name) => User(name: name),
    ),
  );

  ...
}

Caveats

Since shared_preferences keeps all its data in memory, it's not recommended to use this cache for services with large states. In such cases, consider using a different cache implementation.