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

Datasource caching #2214

Open
BenjyWiener opened this issue Aug 21, 2024 · 4 comments
Open

Datasource caching #2214

BenjyWiener opened this issue Aug 21, 2024 · 4 comments

Comments

@BenjyWiener
Copy link

I have a large JSON datasource that's used in a nested template, which is executed many times in a loop.

I currently load the datasource at the top level and use dict to pass the value along with the actual context to the nested template.

I would like to be able to load the datasource from the nested template where it's used, but the runtime impact of reading and deserializing the JSON file each iteration is huge (50-100x slower in my case). An option to cache datasource reads would solve this.

Possible mechanisms:

  1. cache option in config file and/or as query parameter

  2. A new function that caches datasource reads (datasourceCached)

  3. A more general set of functions that allow writing to and reading from some global "state".

@hairyhenderson
Copy link
Owner

An option to cache datasource reads

datasource reads are already cached, though I don't think it's documented...

If you use the --context flag to load datasources, they're read once at startup and always held in memory. If you use --datasource then reference with the datasource/ds function, the data is cached at first read.

@hairyhenderson hairyhenderson closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2024
@BenjyWiener
Copy link
Author

BenjyWiener commented Sep 18, 2024

Thanks for the reply.

Looking at the source code, I see that the string content of the datasource is cached, but not the parsed result.

I'm working with a large JSON file, so the time it takes to parse each time results in a ~100x slowdown compared to using context.

@hairyhenderson
Copy link
Owner

@BenjyWiener ah. is using context an option? Usually I recommend that anyway, given the simpler syntax.

Reopening since there may be a possible feature request here...

@BenjyWiener
Copy link
Author

I'm currently using context, but I use a lot of nested/recursive templates, which requires a lot of {{ template "..." (dict "current_item" . "top_level" $.top_level) }}.

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

No branches or pull requests

2 participants