 PRIVATE>
 
 : purge-cache ( cache -- )
-    dup max-age>> '[
-        [ nip [ 1 + ] change-age age>> _ < ] assoc-partition
-        values dispose-each
-    ] change-assoc drop ;
+    [ assoc>> ] [ max-age>> ] bi '[
+        [
+            nip dup age>> 1 + [ >>age ] keep
+            _ < [ drop t ] [ dispose, f ] if
+        ] assoc-filter! drop
+    ] { } make [ last rethrow ] unless-empty ;

! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel assocs math accessors destructors fry sequences ;
IN: cache

TUPLE: cache-assoc < disposable assoc max-age ;

    assoc>> set-at ;

M: cache-assoc clear-assoc
    assoc>> [ values dispose-each ] [ clear-assoc ] bi ;

M: cache-assoc >alist assoc>> [ value>> ] { } assoc-map-as ;

