Skip to content

Allow callers to supply the JsonLogic parse cache - #69

Open
siddarthaboddu wants to merge 1 commit into
jamsesso:mainfrom
siddarthaboddu:codex/caller-supplied-parse-cache
Open

siddarthaboddu wants to merge 1 commit into
jamsesso:mainfrom
siddarthaboddu:codex/caller-supplied-parse-cache

Conversation

@siddarthaboddu

Copy link
Copy Markdown

A long-lived JsonLogic instance retains every distinct rule string it parses. This adds JsonLogic.withParseCache(...) so applications can control eviction and expiry using a dedicated ConcurrentMap<String, JsonLogicNode>.

An application using Caffeine can configure its cache once:

Cache<String, JsonLogicNode> cache = Caffeine.newBuilder().maximumSize(1_000).build();
JsonLogic logic = JsonLogic.withParseCache(cache.asMap());

Existing apply(rule, data) calls continue to work. Each call evaluates the parsed rule against its current input, even if the cache evicts the entry during that call. The default constructor retains its existing unbounded cache. Caffeine stays in the consuming application.

Concurrent misses can parse the same rule more than once. With Caffeine 2.x, map lookups bypass its hit and miss counters.

The full JUnit suite passed (113 tests), including new coverage for reuse, caller-driven eviction, immediate eviction, and null-cache rejection. A separate integration check passed with Caffeine 2.9.3.

Related to #45. Follows up on the maintainer feedback in #56.

Accept a caller-owned ConcurrentMap through JsonLogic.withParseCache so
applications can choose how long to retain parsed rules. Keep the
default constructor's unbounded cache and existing apply calls.

Evaluate the node obtained during lookup or insertion so eviction
during a call cannot discard the rule being evaluated.

Refs jamsesso#45

This branch has not been deployed

No deployments
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