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

TitaniumJsonLd context caching loads document on every call #4232

Closed
ricardas-buc opened this issue Jun 4, 2024 · 3 comments · Fixed by #4236
Closed

TitaniumJsonLd context caching loads document on every call #4232

ricardas-buc opened this issue Jun 4, 2024 · 3 comments · Fixed by #4236
Assignees
Labels
enhancement New feature or request

Comments

@ricardas-buc
Copy link

Bug Report

Describe the Bug

A mixup of orElse VS orElseGet causes document to be loaded every time, even though cache is being hit.

return Optional.ofNullable(documentCache.get(uri))
.orElse(loader.loadDocument(uri, options));

Expected Behavior

Cached document should not be loaded again.

Context Information

  • Used version EDC 0.7

Detailed Description

If applicable, add screenshots and logs to help explain your problem.

Possible Implementation

Switching to orElseGet solves the issue. This does save extra 2-5ms per execution.

@github-actions github-actions bot added the triage all new issues awaiting classification label Jun 4, 2024
@ndr-brt ndr-brt added enhancement New feature or request and removed triage all new issues awaiting classification labels Jun 4, 2024
@ndr-brt
Copy link
Member

ndr-brt commented Jun 4, 2024

thanks for reporting, would you like to provide a PR to implement this enhancement? (definitely not a bug)

@ricardas-buc
Copy link
Author

I would not agree that it is not a bug, document cache is not being properly utilized :) In any case it should be a simple fix:

            var document = Optional.ofNullable(documentCache.get(uri));
            if (document.isEmpty()) {
                return loader.loadDocument(uri, options);
            }
            return document.get();

using orElseGet would require additional code to handle JsonLdError exception, but this way it is rather straightforward. If PR is still required, then this will have to wait, not enough resources on my end for it to happen this week.

@ndr-brt
Copy link
Member

ndr-brt commented Jun 5, 2024

@ricardas-buc no worries, a PR has been already opened for this enhancement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants