@@ -6,8 +6,8 @@ The [XML Resolver](https://github.com/xmlresolver/xmlresolver) can be configured
6
6
automatically cache resources that it accesses on the web. This tool allows you to
7
7
inspect and update the cache.
8
8
9
- It has five commands: show, inspect, create, update, and flush. These are accessed
10
- from the command line:
9
+ It has six commands: show, inspect, create, update, delete, and flush.
10
+ These are accessed from the command line:
11
11
12
12
```
13
13
Usage: CacheCtrl [options] [command] [command options]
@@ -63,34 +63,185 @@ Usage: CacheCtrl [options] [command] [command options]
63
63
-space
64
64
The maximum space the entries are allowed
65
65
66
+ delete Create a new cache configuration
67
+ Usage: delete [options]
68
+ Options:
69
+ * -pattern
70
+ The URI regular expression pattern
71
+
66
72
flush Flush the cache
67
73
Usage: flush [options]
68
74
Options:
69
- -pattern
70
- The URI regular expression pattern
71
- -regex, -r
75
+ * -regex, -r
72
76
A regular expression to filter the entries shown
73
77
```
74
78
75
- ## show
79
+ ## Commands
80
+
81
+ ### show
76
82
77
83
The ` show ` command will show you what is in the cache.
78
84
79
- ## inspect
85
+ ### inspect
80
86
81
87
The ` inspect ` command will show you how the cache is configured. The
82
88
cache control parameters can be configured on a per-URI basis. For
83
89
example, you could cache resources from some sites longer than others,
84
90
or allow some to have larger caches.
85
91
86
- ## create and update
92
+ ### create and update
87
93
88
94
The ` create ` and ` update ` commands modify the cache control parameters
89
95
for a particular pattern. They are the same except that the pattern
90
96
you specify for ` create ` must not exist and the pattern you specify
91
97
for ` update ` must exist.
92
98
93
- ## flush
99
+ ### delete
100
+
101
+ The ` delete ` command removes a cache pattern.
102
+
103
+ ### flush
94
104
95
105
The ` flush ` command will delete resources from the cache.
96
106
107
+ ## Examples
108
+
109
+ The cache directory can be configured in a ` .xmlresolver.properties ` file or via
110
+ system properties. In these examples, we’ve got the cache in ` $HOME/.xmlresolver/cache ` .
111
+
112
+ First, we can inspect the default settings:
113
+
114
+ ```
115
+ $ java -jar xmlresolver-cachectrl.jar inspect
116
+ Cache directory: /usr/local/share/xmlresolver/cache
117
+ Cache exclude ^file:
118
+ Cache exclude ^jar:file:
119
+ Cache exclude ^classpath:
120
+ Cache include .*
121
+ Files: 0.00 bytes in 0 entries
122
+ Limits: 10.00mb, 1000 entries, delete wait 7d
123
+ ```
124
+
125
+ The last pattern ` .* ` is the default pattern. You can’t delete that one, but you can
126
+ add your own pattern matching ` .* ` if you wish to provide different defaults.
127
+
128
+ Next, let’s update the cache so that it will store DocBook and JATS resources
129
+ differently:
130
+
131
+ ```
132
+ $ java -jar xmlresolver-cachectrl.jar create -pattern:"https://.*docbook\.org" -size 10k -space 100m
133
+ Cache directory: /usr/local/share/xmlresolver/cache
134
+ Cache exclude ^file:
135
+ Cache exclude ^jar:file:
136
+ Cache exclude ^classpath:
137
+ Cache include https://.*docbook\.org/
138
+ Files: 0.00 bytes in 0 entries
139
+ Limits: 100.00mb, 10240 entries, delete wait 7d
140
+ Cache include .*
141
+ Files: 0.00 bytes in 0 entries
142
+ Limits: 10.00mb, 1000 entries, delete wait 7d
143
+ ```
144
+
145
+ This allows up to 10,240 resources occupying at most 100mb of space to be cached
146
+ from URIs that match “https://.* docbook\. org”. That will include both docbook.org
147
+ and cdn.docbook.org.
148
+
149
+ For JATS, let’s try this:
150
+
151
+ ```
152
+ $ java -jar xmlresolver-cachectrl.jar create -pattern:https://jats.nlm.nih.gov/ -size 2k -space 20m -age 30d -delete 1d
153
+ Cache directory: /usr/local/share/xmlresolver/cache
154
+ Cache exclude ^file:
155
+ Cache exclude ^jar:file:
156
+ Cache exclude ^classpath:
157
+ Cache include https://.*docbook\.org/
158
+ Files: 0.00 bytes in 0 entries
159
+ Limits: 100.00mb, 10240 entries, delete wait 7d
160
+ Cache include https://jats.nlm.nih.gov/
161
+ Files: 0.00 bytes in 0 entries
162
+ Limits: 20.00mb, 2048 entries, delete wait 1d, max age: 30d
163
+ Cache include .*
164
+ Files: 0.00 bytes in 0 entries
165
+ Limits: 10.00mb, 1000 entries, delete wait 7d
166
+ ```
167
+
168
+ The JATS portion of the cache will only keep deleted resources for 1 day and will
169
+ only keep any resource for 30 days.
170
+
171
+ Let’s use this cache for a while and accumulate some documents in it. An easy way to do
172
+ this is with the [ SampleApp] ( https://github.com/xmlresolver/sampleapp ) .
173
+
174
+ After parsing and styling a few documents, we see:
175
+
176
+ ```
177
+ $ java -jar xmlresolver-cachectrl.jar inspect
178
+ Cache directory: /usr/local/share/xmlresolver/cache
179
+ Cache exclude ^file:
180
+ Cache exclude ^jar:file:
181
+ Cache exclude ^classpath:
182
+ Cache include https://.*docbook\.org/
183
+ Files: 0.00 bytes in 0 entries
184
+ Limits: 100.00mb, 10240 entries, delete wait 7d
185
+ Cache include https://jats.nlm.nih.gov/
186
+ Files: 0.00 bytes in 0 entries
187
+ Limits: 20.00mb, 2048 entries, delete wait 1d, max age: 30d
188
+ Cache include .*
189
+ Files: 3.19mb in 126 entries
190
+ Limits: 10.00mb, 1000 entries, delete wait 7d
191
+ ```
192
+
193
+ It’s worth noting that these statistics are imperfect. The cache doesn’t
194
+ really keep track of which pattern matched, so these statistics are created by
195
+ testing the cached documents against the patterns.
196
+
197
+ In the case of “.* ”, everything matches. In the case of “public”
198
+ entries, there isn’t a URI to match against.
199
+
200
+ To see what files have been cached, you can show them:
201
+
202
+ ```
203
+ $ java -jar xmlresolver-cachectrl.jar show
204
+ Cache directory: /usr/local/share/xmlresolver/cache
205
+ system https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
206
+ system https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthcustom-modules1.ent
207
+ public -//NLM//DTD JATS (Z39.96) Article Authoring DTD-Specific Modules v1.2 20190208//EN
208
+ system https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-modules1.ent
209
+ …
210
+ uri https://cdn.docbook.org/release/xsltng/current/xslt/locale/cs.xml
211
+ uri https://cdn.docbook.org/release/xsltng/current/xslt/transforms/60-annotations.xsl
212
+ uri https://cdn.docbook.org/release/xsltng/current/xslt/transforms/70-xlinkbase.xsl
213
+ uri https://cdn.docbook.org/release/xsltng/current/xslt/modules/templates.xml
214
+ 126 entries
215
+ ```
216
+
217
+ You can limit the results with a regular expression:
218
+
219
+ ```
220
+ $ java -jar xmlresolver-cachectrl.jar show -r:".*\.dtd"
221
+ Cache directory: /usr/local/share/xmlresolver/cache
222
+ Showing cache entries matching '.*\.dtd'
223
+ system https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
224
+ 1 of 126 entries match
225
+ ```
226
+
227
+ The regular expression is applied to the summary line, not just the URI.
228
+ Consequently, you can match on the entry type:
229
+
230
+ ```
231
+ $ java -jar xmlresolver-cachectrl.jar show -r:"^public "
232
+ Cache directory: /usr/local/share/xmlresolver/cache
233
+ Showing cache entries matching '^public '
234
+ public -//NLM//DTD JATS (Z39.96) Article Authoring DTD-Specific Modules v1.2 20190208//EN
235
+ public -//NLM//DTD JATS (Z39.96) JATS DTD Suite Module of Modules v1.2 20190208//EN
236
+ …
237
+ public -//NLM//DTD JATS (Z39.96) JATS DTD Suite Notation Declarations v1.2 20190208//EN
238
+ 34 of 126 entries match
239
+ ```
240
+
241
+ To get rid of cache entries, you can flush them:
242
+
243
+ ```
244
+ $ java -jar xmlresolver-cachectrl.jar flush -r:"https://cdn\.docbook"
245
+ Cache directory: /usr/local/share/xmlresolver/cache
246
+ Flushed 57 entries
247
+ ```
0 commit comments