Cache system code overview

From RetroShare
Jump to: navigation, search

Contents

Diagram

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

The Cache system works as a series of CacheSources and CacheStores. (Click to view full resoluton)

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.

<source lang="cpp"> 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)

};

</source>

CacheStore

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

<source lang="cpp"> class CacheStore {

       public:
       // Constructor etc ... (removed for clarity)
       /* virtual functions overloaded by cache implementor */

virtual int loadCache(const CacheData &data); /* actual load, once data available */

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

}; </source>

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 transfered 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 maschine 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.

Personal tools
Namespaces

Variants
Actions
Navigation
External websites
Wiki
Toolbox