Skip to content

Lazy loading an array #323

@dswitzer

Description

@dswitzer

I have a template in which I'd like to expose an ArrayList to the template, but I want to lazy load the array since it's not going to be commonly used and can be expensive to generate.

From the best that I can tell, lazy loading only works with objects that will create a Map so the only strategy for lazy loading an array would be to actually create a map that returns the array as a key. So my context would have to look something like:

Entity.History.Items

So I can have History value be a POJO or implementation of LiquidSupport, but I have to return a Map, so the actual array needs to be in another key (i.e. Items).

However, I'd really like to just use Entity.HistoryItems and have HistoryItems be a lazy loaded array.

Is there anything I'm missing? Is there a technique I'm missing which would allow any request to HistoryItems to lazy load and have it return any type of object?

For example, maybe the value of a specific key is a String/Long/etc that is just costly to calculate, so you only want to expose it if the user needs it. For example, we do some duration calculations that take working hours into account, which is extremely expensive to calculate. So ideally I'd only generate that information if it's actually needed.

The only other strategy I could think of was to parse the template first, find out which context keys are being requested and then only return the context needed. However, that's not a strategy I think will scale well and it's one I'd like to avoid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions