-
-
Notifications
You must be signed in to change notification settings - Fork 463
What are the best practices for lazy loading? #612
-
Assumption that an expression is dynamic, so not all the required data is known in advance.
Example:
sometimes the expression is:
foo + bar
another time can be only:
bar
If fetch for foo needs web request , how to avoid web request for each time and only fetch and set value of foo to env when found in expression?
I think it's a very normal case in business projects.For example, in a marketing system, the combination of conditions can be very flexible, and the data sources for these conditions include basic account information, order information, login information, and so on.
Different combinations of conditions require fetching different combinations of entities(Account, Order , Login...). Pre-fetching all the data every time would result in wastage of resources. It is desired to dynamically retrieve the data sources when evaluating a specific condition and cache the data sources to the environment (env).
Beta Was this translation helpful? Give feedback.
All reactions
@BubbleGarten @antonmedv A way to do it without patching is to replace all dynamically populated variables by 'getter's. Static variables can be used as is.
Thus, the expression becomes : getFoo() + getBar() + baz. You can have an arbitrary amount of intelligence in the getters to decide whether you want to download content or use a local cache or something else.
Replies: 2 comments 1 reply
-
@antonmedv Could you please kindly provide some suggestions ?
Beta Was this translation helpful? Give feedback.
All reactions
-
Use patcher to replace expression to func calls:
foo() + bar()
Beta Was this translation helpful? Give feedback.
All reactions
-
@BubbleGarten @antonmedv A way to do it without patching is to replace all dynamically populated variables by 'getter's. Static variables can be used as is.
Thus, the expression becomes : getFoo() + getBar() + baz. You can have an arbitrary amount of intelligence in the getters to decide whether you want to download content or use a local cache or something else.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1