Repository navigation
feat: add activation cache support #23
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6ea48d4
feat: add activation cache support
k13gomez 91b13c2
feat: allow default props on queries too, same as rules
k13gomez 9f323ec
chore: update default props to better reflect that it includes queries
k13gomez 91d3822
Revert "feat: allow default props on queries too, same as rules"
k13gomez 38a7f5e
feat: handle MR feedback, renaming cache to activation-cache
k13gomez 8158509
chore: better destructuring of options
k13gomez d1d71d2
feat: update build-cache-key, general engine cleanup, minimize dynamic
k13gomez d39a9e2
chore: add another test to verify reusable cache between sessions
k13gomez 6494928
chore: cleanup docs and fix compiler-cache resolution
k13gomez b75eccc
chore: upgrade deps to latest
k13gomez aa04e10
chore: lint fixes after updating clj-kondo linter
k13gomez 2140b04
feat: update deps to latest and ensure replayed activations are traced
k13gomez 8ef5731
fix: setup clojure and java for ci through gh actions, fix mise cfg
k13gomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| (ns clara.rules.activation-cache.core | ||
| "Support for caching the output of rule right-hand-side (RHS) activations | ||
| so it can be replayed across rules sessions instead of recomputed. | ||
|
|
||
| The engine consults a cache the caller supplies via the `:activation-cache` | ||
| fire-rules option: an atom wrapping any `clojure.core.cache/CacheProtocol` implementation. | ||
| A rule opts in via its own `:cache` prop. This namespace provides | ||
| `build-cache-key`, which derives the key an activation is cached under (callers | ||
| can override it per fire with the `:activation-cache-key-fn` fire-rules option). Any | ||
| policy beyond basic lookup/hit/miss — TTL, tracking which entries were | ||
| consulted, sweeping at the end of a run — is the responsibility of the caller's | ||
| cache implementation.") | ||
|
|
||
| (defn build-cache-key | ||
| "Builds an activation cache key for the given activation (a map with `:node` and | ||
| `:token`). | ||
|
|
||
| The key is the data the RHS output depends on: the rule's environment, name, | ||
| props, and the bindings it fired on. The rule name and namespace version are | ||
| already encoded in the rule's `:name`/`:props` by the caller, so this key | ||
| changes exactly when the rule logic or its inputs change. The full bindings are | ||
| stored (not a hash) so a deserialized key compares `=` to a freshly-computed | ||
| one with no chance of collision." | ||
| [{:keys [node token]}] | ||
| (let [{:keys [production]} node | ||
| {:keys [bindings]} token | ||
| rule-name (:name production) | ||
| rule-env (or (:env production) {}) | ||
| rule-props (or (:props production) {})] | ||
| {:env rule-env | ||
| :name rule-name | ||
| :props rule-props | ||
| :bindings bindings})) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.