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

Add @CacheKey() annotation #55

Closed
7 tasks done
Axot017 opened this issue Jun 7, 2022 · 2 comments
Closed
7 tasks done

Add @CacheKey() annotation #55

Axot017 opened this issue Jun 7, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@Axot017
Copy link
Contributor

Axot017 commented Jun 7, 2022

Add CacheKey annotation which will allow developers to pass function which will generate cache key (by default hashCode is used as a cache key).

  • Create @CacheKey annotation that will take one param with type String Function(dynamic)
  • Validate if @CacheKey is not used with @Ignore or @ignoreCache annotations
  • Create generation logic that will replace hashKey with result of function passed in @CachedKey annotation
  • Write generation tests
  • Write integration tests
  • Write dart doc for @cacheKey
  • Add section in README.md for @cacheKey

Example usage:

String getListCacheKeys(Iterable<Object> l) {
  return l.map((e) => e.hashCode).join('')
}

@withCache
class Example {
  String doSomething(@CacheKey(getListCacheKeys) List<SomeObject> l) {
    return 'something';
  }
}

To discus:
Maybe we should create also something like @iterableCacheKey which will handle case described in "example usage" as its quite generic.

@Axot017 Axot017 added this to the v1.1.0 milestone Jun 7, 2022
@Axot017 Axot017 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jun 7, 2022
@RSC-88
Copy link
Member

RSC-88 commented Jun 10, 2022

Hello, I think it is very good idea to create new decorator like "iterableCacheKey".

@dannnoon
Copy link

I believe it's a key feature 😏
We should think about what is the best way to generate hashcode for the list of items
Java way is to iterate through elements and multiply the list by the prime number, then add hash of the next item
result = result * prime + nextItem.hashCode

@Axot017 Axot017 closed this as completed Jun 22, 2022
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 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants