What does it mean by $scope=global in ATG..?

自闭症网瘾萝莉.ら 提交于 2019-12-04 16:10:28

Historically there were three different types of scope available in ATG. This has now increased to 5, with the addition of Window (generally only used in the CSC application so try not to use it) and Prototype (added to support the use of Endeca Cartridge Handlers).

As you highlight from the documentation, global component is instantiated once and is shared by all users, while a session component is created once for a given session and is shared by all requests of that session. Similarly a request scoped component is freshly instantiated for each request that uses it.

From a performance point of view, resolving the path to an existing component (for example a globally scoped component like ForEach) takes a little time, but instantiating a new object (in other words a request scoped component) is comparatively more expensive.

So in the case of a ForEach droplet it gets instantiated once but in the service method it actually extracts the parameters from the request:

String elementName = pRequest.getParameter(ELEMENT_NAME);

This means that your globally scoped component is thread safe in that it only takes in parameter from the current request. So in general, if a component can be shared by multiple users, without worrying about synchronisation, it should be globally scoped versus session or request scoped. (The rule of thumb should be that if your droplet is request scoped, you are likely doing it wrong).

If you are aware of Design Patterns, $scope=global is the equivalent of making an ATG component a singleton.

ATG Commerce has 4 different scopes of components

  1. Global: This is the default scope of the component, if scope isn’t defined. These components will be initialized once and will be there as a global object. It’s a best practice to have all the Droplets, Tools, Manager and other Configuration components as global
  2. Session: The scope and the values maintained will be unique for every session. The session scope components generally used are ShoppingCart (Order), Profile, SearchFormHandler etc..
  3. Request:The scope and the values maintained will be unique for every request. The request scope components generally used are FormHandlers to process individual requests.
  4. Window: The scope and the values maintained will be unique till the browser window is closed. The Window scope components
    generally used in CSC application for ShoppingCart component etc.. It’s good to use components with any scope based on business
    requirement but having it declared as Global and using it will be a benificial for improving the performance of the application. It’s a thumb rule have the business logic in Global scope components and refer it from lower scoped components if required. This will reduce the threads waiting to be Garbage collected.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!