comparison xml/en/docs/stream/ngx_stream_js_module.xml @ 2990:7e83ebfac8ca

Documented the js_shared_dict_zone directive.
author Yaroslav Zhuravlev <yar@nginx.com>
date Thu, 06 Jul 2023 12:31:31 +0100
parents 3cc6e38246b1
children 98bd95a5ac70
comparison
equal deleted inserted replaced
2989:703d3450cd81 2990:7e83ebfac8ca
7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> 7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
8 8
9 <module name="Module ngx_stream_js_module" 9 <module name="Module ngx_stream_js_module"
10 link="/en/docs/stream/ngx_stream_js_module.html" 10 link="/en/docs/stream/ngx_stream_js_module.html"
11 lang="en" 11 lang="en"
12 rev="35"> 12 rev="36">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 The <literal>ngx_stream_js_module</literal> module is used to implement 17 The <literal>ngx_stream_js_module</literal> module is used to implement
606 </para> 606 </para>
607 607
608 </directive> 608 </directive>
609 609
610 610
611 <directive name="js_shared_dict_zone">
612 <syntax>
613 <literal>zone</literal>=<value>name</value>:<value>size</value>
614 [<literal>timeout</literal>=<value>time</value>]
615 [<literal>type</literal>=<literal>string</literal>|<literal>number</literal>]
616 [<literal>evict</literal>]</syntax>
617 <default/>
618 <context>stream</context>
619 <appeared-in>0.8.0</appeared-in>
620
621 <para>
622 Sets the <value>name</value> and <value>size</value> of the shared memory zone
623 that keeps the key-value dictionary
624 shared between worker processes.
625 </para>
626
627 <para>
628 By default the shared dictionary uses a string as a key and a value.
629 The optional <literal>type</literal> parameter
630 allows redefining the value type to number.
631 </para>
632
633 <para>
634 The optional <literal>timeout</literal> parameter sets
635 the time after which all shared dictionary entries are removed from the zone.
636 </para>
637
638 <para>
639 The optional <literal>evict</literal> parameter removes the oldest
640 key-value pair when the zone storage is exhausted.
641 </para>
642
643 <para>
644 Examples:
645 <example>
646 example.conf:
647 # Creates a 1Mb dictionary with string values,
648 # removes key-value pairs after 60 seconds of inactivity:
649 js_shared_dict_zone zone=foo:1M timeout=60s;
650
651 # Creates a 512Kb dictionary with string values,
652 # forcibly removes oldest key-value pairs when the zone is exhausted:
653 js_shared_dict_zone zone=bar:512K timeout=30s evict;
654
655 # Creates a 32Kb permanent dictionary with number values:
656 js_shared_dict_zone zone=num:32k type=number;
657
658 example.js:
659 function get(r) {
660 r.return(200, ngx.shared.foo.get(r.args.key));
661 }
662
663 function set(r) {
664 r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));
665 }
666
667 function delete(r) {
668 r.return(200, ngx.shared.bar.delete(r.args.key));
669 }
670
671 function increment(r) {
672 r.return(200, ngx.shared.num.incr(r.args.key, 2));
673 }
674 </example>
675 </para>
676
677 </directive>
678
679
611 <directive name="js_var"> 680 <directive name="js_var">
612 <syntax><value>$variable</value> [<value>value</value>]</syntax> 681 <syntax><value>$variable</value> [<value>value</value>]</syntax>
613 <default/> 682 <default/>
614 <context>stream</context> 683 <context>stream</context>
615 <context>server</context> 684 <context>server</context>