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

Make secured js cache replaceable #59

Merged
merged 1 commit into from
Jun 23, 2018

Conversation

escitalopram
Copy link

The secured js cache is currently only available per NashornSandbox instance. I have many Sandbox instances, all executing the same script in separate threads, which is effectively beautified on every request. This makes processing very slow for me.

In this pull request, I abstracted out an interface for that cache, so that I can replace it with my own global & thread-safe implementation. However, as concurrent caching is nontrivial and requires additional dependencies, I chose not to include my own concrete implementation of that cache.

@Override
public String getOrCreate(String js, boolean allowNoBraces, Supplier<String> producer) {
assertConfiguration(allowNoBraces);
String result = map.get(js);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this thread-safe here? Maybe it needs to be synchronized so that get() and put() are always executed together?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is supposed to be a reflection of the status quo, and as the javadoc says, is not intended to be thread-safe.

Why?
I'm working with the assumption that the sandbox itself is not thread-safe, and because currently, the cache is per-sandbox, the new default cache, which would also be per-sandbox, does not need to be thread-safe either. As this class is package private, it should not be possible for the user to re-use instances of it across different sandbox instances.

Maybe I am wrong about that initial assumption?

Also, I'd like to state again, that this pull request contains no actual implementation of a concurrent cache, only the interface to have the user put one in.

@mxro
Copy link
Collaborator

mxro commented May 23, 2018

This is an awesome idea! Thank you!

I've already started looking through the code and left one comment there so far!

@escitalopram
Copy link
Author

(In case you were not notified of the code comment: I answered. Any other feedback?)

@mxro mxro merged commit 6aa38d9 into javadelight:master Jun 23, 2018
@mxro
Copy link
Collaborator

mxro commented Jun 23, 2018

Merged and will be released with version 0.1.15. Thank you for the contribution and please excuse the delay in merging it!

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.

2 participants