Skip to content

V1.1.0

Latest
Compare
Choose a tag to compare
@AhmedGoudaa AhmedGoudaa released this 14 Mar 13:09
· 1 commit to main since this release

Release Notes

New Features

  • MemoizeCtx Functions: Introduced a new set of MemoizeCtx functions to support memoization of functions that accept a context.Context parameter. These functions allow for efficient caching and retrieval of results based on input parameters and context, improving performance for expensive or frequently called functions.

    • MemoizeCtx: Memoizes a function with context and no parameters.
    • MemoizeCtx1: Memoizes a function with context and 1 parameter.
    • ... until MemoizeCtx7

Enhancements

  • Hide entries attr of the cache class.
  • Concurrency Support: The MemoizeCtx functions are designed to be thread-safe and concurrent-safe, ensuring reliable performance in multi-threaded environments.

Examples

Basic Memoization with Context

computeCtxFn := func(ctx context.Context) int {
    // Expensive computation
    return 42
}
memoizedCtxFn := MemoizeCtx(computeCtxFn, 10*time.Second)
result := memoizedCtxFn(context.Background())

Memoization with Context and Parameters

computeCtxFn := func(ctx context.Context, a int) int {
    // Expensive computation
    return a * 2
}
memoizedCtxFn := MemoizeCtx1(computeCtxFn, 10*time.Second)
result := memoizedCtxFn(context.Background(), 5)

Bug Fixes

  • N/A

Known Issues

  • N/A

Documentation

  • Updated the README.md to include usage examples and descriptions for the new MemoizeCtx functions.