CachingProxy

From OpenCog

The CachingProxyNode is a ProxyNode that only passes on read requests to another StorageNode, if the requested data is not yet in the current AtomSpace. This includes the reading of Atoms and Values as well as of incoming sets. This is primarily useful to build a caching network server: if a request arrives via the network, it is fulfilled immediately from data in the AtomSpace, if it is there; otherwise the request is passed to another StorageNode (presumably, to get data from disk, or even possibly another network node.)

Example

Suppose you are running a CogServer, and you wish to honor read requests as fast as possible, i.e. to serve them directly out of the AtomSpace, if the data is there. If the data is not there, the fallback is to fetch from disk. This would be accomplished by setting

  (ProxyParameters
     (CachingProxy "right here")
     (List
        (RocksStorageNode "rocks:///tmp/foo.rdb")))

To wire this into CogServer, use the `cog-set-proxy!` and the `cog-proxy-open` commands, as demonstrated in the /examples/atomspace/persist-proxy.scm example.

This is still usable without a cogserver: Just open it and use it like any other StorageNode:

(cog-open (CachingProxy "right here"))

Then you can fetch data:

(fetch-atom (Concept "foo"))

If there are a collection of Values on (Concept "foo"), then nothing happens. Otherwise, the values are fetched from disk. Of course, this can be set up with any StorageNode. So, for example.

  (ProxyParameters
     (CachingProxy "Getnet")
     (List
        (CogStorageNode "cog://aseffa.example.com:17001")))

would fetch missing Atoms from aseffa.example.com.

Large Datasets

This proxy works, but is currently very simplistic. Future iterations will modify it to set a cap on the total size of the AtomSpace (so that the AtomSpace doesn't grow too large). This would allow it to be used as a true cache, on top of humongous datasets living on disk, thus allowing the use of datasets that are too large to live in RAM. This could, for example, allow use on Android devices or on Raspberry Pi: Even without much RAM, large datasets could be accessed from SD cards.

This hasn't been implemented yet, but should actually be pretty simple to do. Contact Linas if interested in this.

See also