| 4D v20.1Storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
    4D v20.1
 Storage 
         | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Storage -> Function result | ||||||||
| Parameter | Type | Description | ||||||
| Function result | Object |   | Catalog of shared objects and shared collections registered in Storage | |||||
The Storage method returns the catalog of shared objects or shared collections that you have registered in the Storage object on the current machine or component.
The catalog returned by Storage is automatically created by 4D and is available to all processes of the database, including preemptive processes. There is one Storage catalog per machine and component: in a client/server application, there is one Storage shared object on the server, and one Storage shared object on each remote 4D application; if the database uses components, there is one Storage object per component.
Use the Storage catalog to reference any shared objects or shared collections that you want to be used from any preemptive or standard process. To register a shared object or a shared collection in the catalog, add its reference to the shared object returned by Storage.
Since the catalog returned by Storage is a shared object, it follows the rules described in the Shared objects and shared collections section, but with some specificities:
A common practice could be initializing the Storage object in the :
 Use(Storage)
    Storage.counters:=New shared object("customers";0;"invoices";0)
 End useThis example shows a standard way to set Storage values:
 Use(Storage)
    Storage.mydata:=New shared object
    Use(Storage.mydata)
       Storage.mydata.prop1:="Smith"
       Storage.mydata.prop2:=100
    End use
 End useStorage allows implementing a singleton with a lazy initialization, as shown in the following example.
Note: For more information about singleton patterns, you can refer to this Wikipedia page.
 C_LONGINT($0)
 C_LONGINT($counterValue)
 C_OBJECT(counter) //create a reference to counter for the process
 
 If(counter=Null) //if this reference is null, get if from Storage
    Use(Storage) //Use of Storage needed only once!
       If(Storage.counter=Null)
          Storage.counter:=New shared object("operation";0)
       End if
       counter:=Storage.counter //Get the reference of the counter shared object
    End use
 End if
 Use(counter) //directly use the shared object counter (no need to use Storage!)
    counter.operation:=counter.operation+1
    $counterValue:=counter.operation
 End use
 
 $0:=$counterValue
	Product:  4D
	Theme:  Objects (Language)
	Number:  
        1525
        
        
        
	
	Created:  4D v16 R6
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	4D Language Reference ( 4D v20)
	
	
	4D Language Reference ( 4D v20.1)
	
	
	
 Add a comment
Add a comment