Liking cljdoc? Tell your friends :D

methodical.impl.cache.watching

A Cache implementation that wraps any other cache, watching one or more references (such as an atom or var), calling clear-cache! whenever one of those references changes.

WatchingCaches can be created by calling add-watches on another cache. add-watches is composable, meaning you can thread multiple calls to it to build a cache that watches the entire world go by. You could, for example, use this to build a multifn that supports a dynamic set of hierarchies, letting you add more as you go. The world's your oyster!

WatchingCaches' watch functions weakly reference their caches, meaning they do not prevent garbage collection of potentially large method maps; they also automatically clear out their watches when they are garbage collected and finalized (which, of course, may actually be never -- but worst-case is that some unneeded calls to clear-cache! get made).

A `Cache` implementation that wraps any other cache, watching one or more references (such as an
atom or var), calling `clear-cache!` whenever one of those references changes.

WatchingCaches can be created by calling `add-watches` on another cache. `add-watches` is composable, meaning you
can thread multiple calls to it to build a cache that watches the entire world go by. You could, for example, use
this to build a multifn that supports a dynamic set of hierarchies, letting you add more as you go. The world's your
oyster!

WatchingCaches' watch functions weakly reference their caches, meaning they do not prevent garbage collection of
potentially large method maps; they also automatically clear out their watches when they are garbage collected and
finalized (which, of course, may actually be never -- but worst-case is that some unneeded calls to `clear-cache!`
get made).
raw docstring

add-watchesclj

(add-watches cache refs)

Create a new cache that watches refs (such as vars or atoms), clearing the cache it wraps whenever one of the watched refs changes.

  • If refs is empty (i.e., there's nothing to watch), or cache is already watching the same set of refs, this function this function returns cache as-is.

  • If cache is a WatchingCache with a different set of refs, this returns a flattened WatchingCache that both the orignal refs and the new ones. The original cache is unmodified.

Create a new cache that watches `refs` (such as vars or atoms), clearing the `cache` it wraps whenever one of the
watched refs changes.

*  If `refs` is empty (i.e., there's nothing to watch), or `cache` is already watching the same set of `refs`, this
   function this function returns `cache` as-is.

* If `cache` is a WatchingCache with a *different* set of refs, this returns a flattened WatchingCache that both the
  orignal refs and the new ones. The original `cache` is unmodified.
sourceraw docstring

remove-watchesclj

(remove-watches cache)

Recursively removes all watches from cache, and returning the cache it wrapped (in case you want to thread it into add-watches to watch something else). If cache is not an instance of WatchingCache, returns the cache as-is.

Recursively removes all watches from `cache`, and returning the cache it wrapped (in case you want to thread it into
`add-watches` to watch something else). If `cache` is not an instance of `WatchingCache`, returns the cache as-is.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close