Scope: managed applications, mobile applications, and ordinary applications.
1. Common modules with repeated use of return values (cache) are used to cache results of function operations upon calls or sessions. Use cache not to slow down server performance and to minimize client/server interaction.
See also: chapter "Repeated use of return values" of 1C:Enterprise Development Standards,
Using values affecting client application behavior
2. Excessive use of common modules with reusable return values can increase memory consumption.
2.1. Do not create common modules, which return data that is calculated faster than received from cache. String constants are one of examples. Receiving string constants from common modules with reusable return values takes longer time than recomputing string constants. It also occupies cache memory.
For example, do not place the following in modules with reusable return values:
Function ManagementPackageName() Export
It makes sense to cache data received from the database, external sources, or data obtained as a result of complex (resource-intensive) computations. In some cases, do not cache values obtained from the database because their calculation does not take much time. For example, do not cache constants (metadata object) of primitive types as their calculation does not add up much to the total time of resource-intensive operation execution.
Keep in mind that cache stores data for a limited period of time. A cached value is deleted from cache in 20 minutes following computation or 6 minutes after the last request (whichever one comes first*). Besides, the value will be deleted when a server working process runs out of memory, when a working process is restarted, or when the client switches to another working process. So if nobody uses cached data, the resource is wasted.
* Note: specific figures can vary depending on the used 1C:Enterprise platform version.
2.3. The value range of input parameters of functions placed in reusable common modules must not be too broad.
For example, let's suppose that a configuration includes a function that inputs a counterparty. If there are a lot of counterparties in the database and users are not likely to request the same counterparty in 5 minutes, the recourses are wasted. If you multiply this waste by the number of concurrent users, inefficient memory consumption becomes significant.
3. Do not edit data retrieved from cache. Otherwise, hidden errors might occur in the application and memory is consumed inefficiently. We recommend that you use values whose states cannot be changed as return values. For example: FixedArray, FixedStructure.
This restriction is imposed as cache returns a reference to the same object every time, not an object copy. For example, if you keep adding new values to an array returned by a reusable function upon each call when posting documents, cache becomes overloaded very quickly. Besides, every time cache is cleared, added values will be deleted and the code based on these values will not function correctly.
4. Keep in mind that if a module with reusable return values contains multiple export functions that can both be called externally and call each other, the result of internal calls is not cached.
For example, if the DataExchangeCached module contains two export functions:
Function StandaloneModeSupported() Export
Function IsStandaloneWorkplace() Export
Return StandaloneModeSupported() AND ...;
which are sequentially called from the application code,
... = DataExchangeCached.StandaloneModeSupported();
... = DataExchangeCached.IsStandaloneWorkplace();
the StandaloneModeSupported function is calculated twice.
To always obtain its return value from cache, explicitly specify a module name:
Function IsStandaloneWorkplace() Export
Return DataExchangeCached.StandaloneModeSupported() AND ...;
5. If the "Repeated use of return values" property of a common module is set to "During session", you cannot use values of the TempTablesManager and Query types, and database objects (for example, DocumentObject and ReportObject) in values returned by functions of this modele both directly and in collections. This restriction is imposed as values of these types can only be used in the same server call where they were created.
The platform does not check return of values of these types in specified functions, which leads to application shutdown that is difficult to diagnose (records are stored in the technological log only).
This restriction applies to values used in the temporary storage.