-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.html
531 lines (434 loc) · 20.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>clojure.core.memoize - A manipulable, pluggable, memoization framework 0.5.10 API documentation</title>
<link rel="icon" href="static/favicon.png" />
<link rel="shortcut icon" href="static/favicon.png" />
<link rel="stylesheet" href="static/clojure.css" type="text/css" media="all" />
<link rel="stylesheet" href="static/wiki.css" type="text/css" media="all" />
<link rel="stylesheet" href="static/internal.css" type="text/css" media="all" />
<style>.menuWrapper{height: 36px;}</style>
</head>
<!--
This document was auto-generated from the source by the clojure autodoc system.
To report errors or ask questions about the overall documentation structure, formatting,
etc., contact Tom Faulhaber (google mail name: tomfaulhaber).
For errors in the documentation of a particular namespace, contact the author of that
namespace.
-->
<body>
<div id="AllContentContainer">
<div id="Header">
<a href="index.html" id="Logo"><img src="static/clojure-icon.gif" width="100" height="100" alt="Clojure" /></a>
<h1><a href="index.html" id="page-header" title="page header title">core.memoize API Reference</a></h1>
</div>
<div id="leftcolumn"><div style="text-align: center;"></div>
<div class="menu">
<div class="WikiCustomNav WikiElement wiki">
<span class="toc-header"><span id="project-name">A manipulable, pluggable, memoization framework</span> <span id="version">0.5.10</span> API</span><br />
<ul>
<li><a href="index.html" class="wiki_link">Overview</a></li>
<li><a href="api-index.html" class="wiki_link">API Index</a></li>
</ul>
<a class="wiki_link" href="http://clojure.org">Clojure Home</a>
</div>
</div>
</div>
<div id="rightcolumn">
<div id="Content">
<div class="contentBox"><div class="innerContentBox">
<div class="wiki wikiPage" id="content_view">
<div id="right-sidebar"><div id="toc">
<h1 class="nopad">Table of Contents</h1>
<div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#toc0">Overview</a>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#"></a>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#type-section">Types</a>
<div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/PluggableMemoization" class="toc-entry-anchor">PluggableMemoization</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/RetryingDelay" class="toc-entry-anchor">RetryingDelay</a>
</div>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#var-section">Vars and Functions</a>
<div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/->PluggableMemoization" class="toc-entry-anchor">->PluggableMemoization</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/->RetryingDelay" class="toc-entry-anchor">->RetryingDelay</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/build-memoizer" class="toc-entry-anchor">build-memoizer</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/fifo" class="toc-entry-anchor">fifo</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/lru" class="toc-entry-anchor">lru</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/lu" class="toc-entry-anchor">lu</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo" class="toc-entry-anchor">memo</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo-clear!" class="toc-entry-anchor">memo-clear!</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo-fifo" class="toc-entry-anchor">memo-fifo</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo-lru" class="toc-entry-anchor">memo-lru</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo-lu" class="toc-entry-anchor">memo-lu</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo-swap!" class="toc-entry-anchor">memo-swap!</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memo-ttl" class="toc-entry-anchor">memo-ttl</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/memoized?" class="toc-entry-anchor">memoized?</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/snapshot" class="toc-entry-anchor">snapshot</a>
</div><div class="toc-entry" style="margin-left: 1em;">
<a href="#clojure.core.memoize/ttl" class="toc-entry-anchor">ttl</a>
</div>
</div><div class="toc-section" style="margin-left: 1em;">
<a style="margin-top: 3px;" href="#"></a>
</div>
</div>
</div>
<div id="content-tag"><h1 id="overview">API for <span id="clojure.core.memoize">clojure.core.memoize</span>
- <span id="header-project">A manipulable, pluggable, memoization framework</span> <span id="header-version">0.5.10</span><span id="header-status-block"> (<span id="header-status">in development</span>)</span>
</h1>
<span id="author-line">by <span id="author-name">fogus</span><br /></span>
<br />Full namespace name: <span id="long-name">clojure.core.memoize</span>
<p></p>
<h2>Overview</h2>
<div id="home-page">Project home page is <a href="http://github.com/clojure/core.memoize/">http://github.com/clojure/core.memoize/</a></div>
<pre id="namespace-docstr">core.memoize is a memoization library offering functionality above Clojure's core `memoize`
function in the following ways:
**Pluggable memoization**
core.memoize allows for different back-end cache implmentations to be used as appropriate without
changing the memoization modus operandi.
**Manipulable memoization**
Because core.memoize allows you to access a function's memoization store, you do interesting things like
clear it, modify it, and save it for later.
</pre>
<br />
<div id="type-section">
<p></p>
<h2>Types</h2>
<div id="type-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/PluggableMemoization">PluggableMemoization</h2>
<span id="type-type">type</span><br />
<pre id="type-docstr"></pre>
Fields: <span id="type-fields">[f cache]</span><br />
Protocols: <span id="type-protocols">clojure.core.cache/CacheProtocol</span><br />
Interfaces: <span id="type-interfaces"></span><br />
</div><div id="type-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/RetryingDelay">RetryingDelay</h2>
<span id="type-type">type</span><br />
<pre id="type-docstr"></pre>
Fields: <span id="type-fields">[fun available? value]</span><br />
Protocols: <span id="type-protocols"></span><br />
Interfaces: <span id="type-interfaces">clojure.lang.IDeref</span><br />
</div>
</div>
<div id="var-section">
<p></p>
<h2>Public Variables and Functions</h2>
<div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/->PluggableMemoization">->PluggableMemoization</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (->PluggableMemoization f cache)
</pre>
<pre id="var-docstr">Positional factory function for class clojure.core.memoize.PluggableMemoization.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L29">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/->RetryingDelay">->RetryingDelay</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (->RetryingDelay fun available? value)
</pre>
<pre id="var-docstr">Positional factory function for class clojure.core.memoize.RetryingDelay.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L52">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/build-memoizer">build-memoizer</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (build-memoizer cache-factory f & args)
</pre>
<pre id="var-docstr">Builds a function that given a function, returns a pluggable memoized
version of it. `build-memoizer` Takes a cache factory function, a function
to memoize, and the arguments to the factory. At least one of those
functions should be the function to be memoized.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L152">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/fifo">fifo</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (fifo f)
(fifo f base)
(fifo f tkey threshold)
(fifo f base key threshold)
</pre>
<pre id="var-docstr">Works the same as the basic memoization function (i.e. `memo`
and `core.memoize` except when a given threshold is breached.
Observe the following:
(require '[clojure.core.memoize :as memo])
(def id (memo/fifo identity :fifo/threshold 2))
(id 42)
(id 43)
(snapshot id)
;=> {[42] 42, [43] 43}
As you see, the limit of `2` has not been breached yet, but
if you call again with another value, then it is:
(id 44)
(snapshot id)
;=> {[44] 44, [43] 43}
That is, the oldest entry `42` is pushed out of the
memoization cache. This is the standard **F**irst **I**n
**F**irst **O**ut behavior.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L242">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/lru">lru</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (lru f)
(lru f base)
(lru f tkey threshold)
(lru f base key threshold)
</pre>
<pre id="var-docstr">Works the same as the basic memoization function (i.e. `memo`
and `core.memoize` except when a given threshold is breached.
Observe the following:
(require '[clojure.core.memoize :as memo])
(def id (memo/lru identity :lru/threshold 2))
(id 42)
(id 43)
(snapshot id)
;=> {[42] 42, [43] 43}
At this point the cache has not yet crossed the set threshold
of `2`, but if you execute yet another call the story will
change:
(id 44)
(snapshot id)
;=> {[44] 44, [43] 43}
At this point the operation of the LRU cache looks exactly
the same at the FIFO cache. However, the difference becomes
apparent on further use:
(id 43)
(id 0)
(snapshot id)
;=> {[0] 0, [43] 43}
As you see, once again calling `id` with the argument `43`
will expose the LRU nature of the underlying cache. That is,
when the threshold is passed, the cache will expel the
**L**east **R**ecently **U**sed element in favor of the new.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L292">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/lu">lu</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (lu f)
(lu f base)
(lu f tkey threshold)
(lu f base key threshold)
</pre>
<pre id="var-docstr">Similar to the implementation of memo-lru, except that this
function removes all cache values whose usage value is
smallest:
(require '[clojure.core.memoize :as memo])
(def id (memo/lu identity :lu/threshold 3))
(id 42)
(id 42)
(id 43)
(id 44)
(snapshot id)
;=> {[44] 44, [42] 42}
The **L**east **U**sed values are cleared on cache misses.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L399">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo">memo</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo f)
(memo f seed)
</pre>
<pre id="var-docstr">Used as a more flexible alternative to Clojure's core `memoization`
function. Memoized functions built using `memo` will respond to
the core.memo manipulable memoization utilities. As a nice bonus,
you can use `memo` in place of `memoize` without any additional
changes.
The default way to use this function is to simply apply a function
that will be memoized. Additionally, you may also supply a map
of the form `'{[42] 42, [108] 108}` where keys are a vector
mapping expected argument values to arity positions. The map values
are the return values of the memoized function.
You can access the memoization cache directly via the `:clojure.core.memoize/cache` key
on the memoized function's metadata. However, it is advised to
use the core.memo primitives instead as implementation details may
change over time.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L171">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo-clear!">memo-clear!</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo-clear! f)
(memo-clear! f args)
</pre>
<pre id="var-docstr">Reaches into an core.memo-memoized function and clears the cache. This is a
destructive operation and should be used with care.
When the second argument is a vector of input arguments, clears cache only
for argument vector.
Keep in mind that depending on what other threads or doing, an
immediate call to `snapshot` may not yield an empty cache. That's
cool though, we've learned to deal with that stuff in Clojure by
now.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L107">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo-fifo">memo-fifo</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo-fifo f)
(memo-fifo f limit)
(memo-fifo f limit base)
</pre>
<pre id="var-docstr">DEPRECATED: Please use clojure.core.memoize/fifo instead.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L231">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo-lru">memo-lru</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo-lru f)
(memo-lru f limit)
(memo-lru f limit base)
</pre>
<pre id="var-docstr">DEPRECATED: Please use clojure.core.memoize/lru instead.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L281">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo-lu">memo-lu</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo-lu f)
(memo-lu f limit)
(memo-lu f limit base)
</pre>
<pre id="var-docstr">DEPRECATED: Please use clojure.core.memoize/lu instead.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L388">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo-swap!">memo-swap!</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo-swap! f base)
</pre>
<pre id="var-docstr">Takes a core.memo-populated function and a map and replaces the memoization cache
with the supplied map. This is potentially some serious voodoo,
since you can effectively change the semantics of a function on the fly.
(def id (memo identity))
(memo-swap! id '{[13] :omg})
(id 13)
;=> :omg
With great power comes ... yadda yadda yadda.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L125">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memo-ttl">memo-ttl</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memo-ttl f)
(memo-ttl f limit)
(memo-ttl f limit base)
</pre>
<pre id="var-docstr">DEPRECATED: Please use clojure.core.memoize/ttl instead.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L342">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/memoized?">memoized?</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (memoized? f)
</pre>
<pre id="var-docstr">Returns true if a function has an core.memo-placed cache, false otherwise.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L102">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/snapshot">snapshot</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (snapshot memoized-fn)
</pre>
<pre id="var-docstr">Returns a snapshot of a core.memo-placed memoization cache. By snapshot
you can infer that what you get is only the cache contents at a
moment in time.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L92">Source</a>
</div><div id="var-entry">
<br />
<hr />
<h2 id="clojure.core.memoize/ttl">ttl</h2>
<span id="var-type">function</span><br />
<pre id="var-usage">Usage: (ttl f)
(ttl f base)
(ttl f tkey threshold)
(ttl f base key threshold)
</pre>
<pre id="var-docstr">Unlike many of the other core.memo memoization functions,
`memo-ttl`'s cache policy is time-based rather than algortihmic
or explicit. When memoizing a function using `memo-ttl` you
should provide a **T**ime **T**o **L**ive parameter in
milliseconds.
(require '[clojure.core.memoize :as memo])
(def id (memo/ttl identity :ttl/threshold 5000))
(id 42)
(snapshot id)
;=> {[42] 42}
... wait 5 seconds ...
(id 43)
(snapshot id)
;=> {[43] 43}
The expired cache entries will be removed on each cache **miss**.</pre>
<pre id="var-specs"></pre>
<a id="var-source" href="https://github.com/clojure/core.memoize/blob/0f82bdd867600e7f526b0688aac6e9b82f70e5ee/src/main/clojure/clojure/core/memoize.clj#L353">Source</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="foot">
<div id="copyright" style="text-align: center;">Copyright 2007-2016 by Rich Hickey and the various contributors</div>
</div>
</div>
<div id="DesignedBy">Logo & site design by <a href="http://www.tomhickey.com" title="Visit Tom Hickey's website.">Tom Hickey</a>.<br />
Clojure auto-documentation system by Tom Faulhaber.</div>
</div>
<!-- /AllContentContainer -->
</body>
</html>