Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Allow editing cache #116

Open
jtdLab opened this issue May 12, 2024 · 0 comments · May be fixed by #119
Open

[Feature]: Allow editing cache #116

jtdLab opened this issue May 12, 2024 · 0 comments · May be fixed by #119
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@jtdLab
Copy link

jtdLab commented May 12, 2024

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

@mateuszfilipek2000 mateuszfilipek2000 self-assigned this Sep 30, 2024
@mateuszfilipek2000 mateuszfilipek2000 added enhancement New feature or request good first issue Good for newcomers labels Sep 30, 2024
@mateuszfilipek2000 mateuszfilipek2000 linked a pull request Oct 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants