Skip to content

Cache system code overview

Jessie RealityFabric edited this page Dec 30, 2015 · 1 revision

Contents

  1. Diagram
  2. CacheSource
  3. CacheStore
  4. How to Transmit and Cache some information over the RetroShare Network
  5. FAQ (for end users)
  6. What is inside the big cache files downloaded ?
  7. Can I limit the storage size occupied by the cache ?

Diagram

Cache System (location: libretroshare/src/dbase) implements Automatic Data Transport and Caching.

The Cache system works as a series of CacheSources and CacheStores.

Filecache overview.png

CacheSource

A CacheSource provides information to the network peers. The Information is stored into a file, and then the refreshCache() function is called. This triggers the information to be sent to all the online peers, where it is received by their CacheStore classes.

eg. When you add a new Link into RS's Link Cloud, this gets sent into the code: to the p3Ranking service. This triggers publishMsg() function, which writes all your current Links to a File, and calls CacheSource::refreshCache() to send it over the network.

class CacheSource {
    public:
    // Constructor etc ... (removed for clarity)

    /* function to load cache file (normally at startup - to be overloaded by inherited class */
    virtual bool loadLocalCache(const CacheData &data);

    /* Functions to control Caches available */
    bool refreshCache(const CacheData &data); bool clearCache(CacheId id);

    // rest of class ... (removed for clarity)
};

CacheStore

At the receiving Peer's side, once the cache file has been transferred it is passed to the relevant CacheStore. This is done by calling CacheStore::loadCache(data).

class CacheStore {
    public:
    // Constructor etc ... (removed for clarity)

    /* virtual functions overloaded by cache implementer */
    virtual int loadCache(const CacheData &data); /* actual load, once data available */

    // rest of class ... (removed for clarity)
};

How to Transmit and Cache some information over the RetroShare Network

  1. Save the data to a file in the cache/local directory.
  2. Inform the Cache System that it is ready to be transferred by calling CacheSource::refreshCache(details).
  3. To receive information, overload CacheStore::loadCache(). This function is called when new information arrives.

FAQ (for end users)

What is inside the big cache files downloaded ?

Q (from a user): While downloading cache files from a couple of new peer I noticed this: most of them are only a few kB each, but some are quite large. I saw some being ~10MB, but just now I downloaded a few of ~50MB and another over 100MB is downloading. From those ~10MB ones I usually got multiple forum messages or new channels, but so far I didn't see anything new from the larger ones.? So the question is - what is/could be inside these caches that makes them so large? Forum and channel messages are just text, so to get a 100MB of text is like getting a good chunk of a book library.

A (from a user): RetroShare can combine cache files so i have 5 000 files combined in 180 MB. If you download some bick pack and all post already on your machine you wouldn't see anything new.

Can I limit the storage size occupied by the cache ?

No, and do not delete the cache files because these will be downloaded again automatically.