]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/cache/cache.factor
core/basis/extra: using STARTUP-HOOK: and SHUTDOWN-HOOK:
[factor.git] / basis / vocabs / cache / cache.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs init kernel memoize namespaces sequences vocabs
4 vocabs.hierarchy vocabs.loader vocabs.metadata vocabs.refresh
5 words ;
6 IN: vocabs.cache
7
8 : reset-vocab-cache ( vocab -- )
9     vocab-name
10     [ root-cache get delete-at ]
11     [
12         \ vocab-file-lines "memoize" word-prop swap
13         '[ drop first vocab-name _ = ] assoc-reject! drop
14     ] bi ;
15
16 : reset-disk-cache ( -- )
17     \ all-disk-vocabs-recursive reset-memoized
18     \ all-authors reset-memoized
19     \ all-tags reset-memoized ;
20
21 : reset-cache ( vocab -- )
22     reset-vocab-cache reset-disk-cache ;
23
24 SINGLETON: cache-observer
25
26 <PRIVATE
27
28 : forgot-vocab? ( vocab -- ? )
29     vocab-name dictionary get key? not ;
30
31 PRIVATE>
32
33 M: cache-observer vocab-changed
34     drop dup forgot-vocab? [ reset-vocab-cache ] [ drop ] if
35     reset-disk-cache ;
36
37 STARTUP-HOOK: [
38     f changed-vocabs set-global
39     cache-observer add-vocab-observer
40 ]