Skip to content

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.

1 participant