3.3.6 About using the most appropriate schema cache
When you use the schema cache functionality, you can reduce the parsing time for validation. However, the problems such as increase in the memory usage or when the disk cache is used, the expected effects might not output.
This subsection describes how to avoid such problems and use the appropriate schema cache.
- Organization of this subsection
(1) Relation of the size and the validation time of schema and instance document
A schema document is coded with XML. The parsing is performed before the validation check, and converted to internal grammar objects. Using cache, you can omit the processing of setting the grammar objects from the schema document. The following time is required for parsing the validation check:
validation-time-of-the-instance-document + time-for-setting-grammar-objects-from-schema-document
The time required for setting grammar objects can be omitted from the cache, so the effect of the schema cache as displayed in the first condition will be more in the following conditions:
-
size-of-the-schema-document > size-of-the-instance-document
-
size-of-the-schema-document < size-of-the-instance-document
(2) Difference between memory cache and disk cache
When using the schema cache functionality, grammar objects are set up from the schema document in advance, so you can omit the time required for setting the grammar objects during the validation.
However, when the memory and the disk cache are used, the time required for parsing the validation check is as follows:
-
Memory cache
For parsing the validation check, the time taken for validating the instance document is required.
-
Disk cache
The following time is required for parsing the validation check:
validation-time-of-the-instance-document + deserialize#-time + I/O-time
- #
-
The processing that converts the data in such a way (serialized) so that the file with all the Java objects can be saved with the format of the original object.
(3) Precautions when using the memory cache
When using the memory cache, after a cache is setup, the cache remains in the memory. Therefore, adjust the memory usage within the permitted range of resources. It is effective to select a schema document that is frequently used, and then using the memory cache with the priority.