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

Initial draft for @lombok.experimental.Memoize #3396

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nea89o
Copy link

@nea89o nea89o commented Apr 5, 2023

This is an initial draft for how an @Memoize annotation could look like. It currently lacks features such as:

  • Thread safety
  • Cache invalidation
  • Soft/Weak References for a lower memory profile
  • Avoiding using a Map entirely for parameterless methods

Ideally at least some of these properties should be configurable using flags and/or annotation properties (some users might prefer a non thread safe cache for better performance).

Example Usage:

class Test {
    int invocationCount = 0;

    public static void main(String[] args) {
        Test test = new Test();
        System.out.println(test.x(1, 2));
        System.out.println(test.x(1, 2));
        System.out.println(test.x(1, 3));
        System.out.println("Invocation Count: " + test.invocationCount);
    }

    @lombok.experimental.Memoize
    public int x(int y, int z) {
        invocationCount++;
        return y + z;
    }
}

This is an initial draft for how an @memoize annotation could look like.
It currently lacks features such as:

 - Thread safety
 - Cache invalidation
 - Soft/Weak References for a lower memory profile
 - Avoiding using a Map entirely for parameterless methods

Ideally at least some of these properties should be configurable using
flags and/or annotation properties (some users might prefer a non
thread safe cache for better performance).

Example Usage:

```java
class Test {
    int invocationCount = 0;

    public static void main(String[] args) {
        Test test = new Test();
        System.out.println(test.x(1, 2));
        System.out.println(test.x(1, 2));
        System.out.println(test.x(1, 3));
        System.out.println("Invocation Count: " + test.invocationCount);
    }

    @lombok.experimental.Memoize
    public int x(int y, int z) {
        invocationCount++;
        return y + z;
    }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant