Mercurial > hg > nginx-site
view xml/en/docs/njs/preload_objects.xml @ 3009:2e8c1384d211
Documented ngx.shared.SharedDict.items in njs Reference.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 12 Sep 2023 21:32:51 +0100 |
parents | 48f245493600 |
children |
line wrap: on
line source
<?xml version="1.0"?> <!-- Copyright (C) Nginx, Inc. --> <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> <article name="Understanding preloaded objects" link="/en/docs/njs/preload_objects.html" lang="en" rev="2" toc="no"> <section id="summary"> <para> For each incoming request njs creates a separate virtual machine. This brings a lot of benefits such as predictable memory consumption or requests isolation. However, as all requests are isolated, if a request handler needs to access some data, it has to read it by itself. This is not efficient especially when the amount of data is large. </para> <para> To address this limitation, a preloaded shared object was introduced. Such objects are created immutable and do not have prototype chains: their values cannot be changed, properties cannot be added or removed. </para> </section> <section id="working_with_preload_objects" name="Working with preload objects"> <para> Here are some examples of how to work with a preload object in njs: <list type="bullet"> <listitem> access properties by name: <programlisting> preloaded_object.prop_name preloaded_object[prop_name] </programlisting> </listitem> <listitem> enumerate properties: <programlisting> for (i in preloaded_object_name) { ... } </programlisting> </listitem> <listitem> apply non-modifying built-in methods using <literal>call()</literal>: <programlisting> Array.prototype.filter.call(preloaded_object_name, ...) </programlisting> </listitem> </list> </para> </section> </article>