1

Can anybody explain why ForEach droplet has global scope, but not request scope?

I mean what this feature give us in performance (real-world app with many users) in comparison if it has the request scope.

bated
  • 960
  • 2
  • 15
  • 29
  • Possible duplicate of [What does it mean by $scope=global in ATG..?](http://stackoverflow.com/questions/18613691/what-does-it-mean-by-scope-global-in-atg) – bated Jul 05 '16 at 20:53

2 Answers2

4

If a component has request scope, it means that an instance (object) of this component will be created (time and memory resources) each time the component is requested. The more often requested - the more time is needed to create an objects. The more user\requests at a time - the more objects at a time. Global scope component are created once and can be re-used by all requests and different users.

ForEach droplet is stateless, can be used by many different requests\users at a time, so there is no reason to make it request scope.

Yekaterina
  • 51
  • 3
0

Global scope means that the component is created only once. Droplets should be stateless because it's easier to use and maintain them. In your particular case, there's no point making ForEach droplet request scope because we can pass a new parameter to iterate through each time we call the droplet. On the other hand Form handlers should have request or session scope because they are intended to process users request, e.g. login process, submitting an order.