Skip to content

[Feature]: Allow editing cache #116

@jtdLab

Description

@jtdLab

Problem

When creating/updating data on a remote data source developers might want to update the local cache after that.

Desired Solution

In the most basic cases something like this could solve it.

Create:

// foo_repository.dart

  @EditCache
  Future<Foo> createFoo(Foo foo) async {
    await dataSource.create(foo);
    return foo;
  }

leading to

// foo_repository.cached.dart

  @override
  Future<Foo> createFoo(Foo foo) async {
    final result = await super.createFoo(foo);
    _getFooCached["${foo.hashCode}"] = result;
    return result;
  }

Update:

// foo_repository.dart

  Future<Foo> getFoo() async {
    // ...
  }

  @EditCache
  Future<Foo> updateFoo(int a, String b) async {
    await dataSource.update(a, b);
    final foo = getFoo();
    return foo.copyWith(a:a, b:b);
  }

leading to

// foo_repository.cached.dart

  @override
  Future<Foo> updateFoo(int a, String b) async {
    final result = await super.updateFoo(a, b);
    _getFooCached["${foo.hashCode}"] = result;
    return result;
  }

Alternatives Considered

No response

On which platorm do you expect this solution?

All

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions