LeechCraft  %{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
LeechCraft::Util::NetworkDiskCache Class Reference

A thread-safe garbage-collected network disk cache. More...

#include "networkdiskcache.h"

+ Inheritance diagram for LeechCraft::Util::NetworkDiskCache:
+ Collaboration diagram for LeechCraft::Util::NetworkDiskCache:

Public Slots

void collectGarbage ()
 Runs the garbage collector. More...
 

Public Member Functions

 NetworkDiskCache (const QString &subpath, QObject *parent=0)
 Constructs the new disk cache. More...
 
 ~NetworkDiskCache ()
 Destroys the cache. More...
 
virtual qint64 cacheSize () const
 Reimplemented from QNetworkDiskCache. More...
 
virtual QIODevice * data (const QUrl &url)
 Reimplemented from QNetworkDiskCache. More...
 
virtual void insert (QIODevice *device)
 Reimplemented from QNetworkDiskCache. More...
 
virtual QNetworkCacheMetaData metaData (const QUrl &url)
 Reimplemented from QNetworkDiskCache. More...
 
virtual QIODevice * prepare (const QNetworkCacheMetaData &)
 Reimplemented from QNetworkDiskCache. More...
 
virtual bool remove (const QUrl &url)
 Reimplemented from QNetworkDiskCache. More...
 
virtual void updateMetaData (const QNetworkCacheMetaData &metaData)
 Reimplemented from QNetworkDiskCache. More...
 

Protected Member Functions

virtual qint64 expire ()
 Reimplemented from QNetworkDiskCache. More...
 

Detailed Description

A thread-safe garbage-collected network disk cache.

This class is thread-safe unlike the original QNetworkDiskCache, thus it can be used from multiple threads simultaneously.

Also, old cache data is automatically removed from the cache in a background thread without blocking. The garbage collection can be also triggered manually via the collectGarbage() slot.

The garbage is collected until cache takes 90% of its maximum size.

Definition at line 57 of file networkdiskcache.h.

Constructor & Destructor Documentation

LeechCraft::Util::NetworkDiskCache::NetworkDiskCache ( const QString &  subpath,
QObject *  parent = 0 
)

Constructs the new disk cache.

The cache uses a subdirectory subpath in the network directory of the user cache location.

Parameters
[in]subpathThe subpath in cache user location.
[in]parentThe parent object of this cache.
See also
GetUserDir(), UserDir::Cache.

Definition at line 45 of file networkdiskcache.cpp.

References LeechCraft::Util::Cache, collectGarbage(), and LeechCraft::Util::GetUserDir().

+ Here is the call graph for this function:

LeechCraft::Util::NetworkDiskCache::~NetworkDiskCache ( )

Destroys the cache.

Destroys the cache object, possibly blocking until the garbage collector finishes if it is running.

Definition at line 60 of file networkdiskcache.cpp.

Member Function Documentation

qint64 LeechCraft::Util::NetworkDiskCache::cacheSize ( ) const
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 66 of file networkdiskcache.cpp.

void LeechCraft::Util::NetworkDiskCache::collectGarbage ( )
slot

Runs the garbage collector.

This function initiates garbage collection in a background thread and returns immediately.

If a collector is already running, this function does nothing.

Definition at line 179 of file networkdiskcache.cpp.

Referenced by expire(), and NetworkDiskCache().

+ Here is the caller graph for this function:

QIODevice * LeechCraft::Util::NetworkDiskCache::data ( const QUrl &  url)
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 71 of file networkdiskcache.cpp.

qint64 LeechCraft::Util::NetworkDiskCache::expire ( )
protectedvirtual

Reimplemented from QNetworkDiskCache.

Runs the garbage collector if required.

See also
collectGarbage()

Definition at line 122 of file networkdiskcache.cpp.

References collectGarbage().

+ Here is the call graph for this function:

void LeechCraft::Util::NetworkDiskCache::insert ( QIODevice *  device)
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 77 of file networkdiskcache.cpp.

QNetworkCacheMetaData LeechCraft::Util::NetworkDiskCache::metaData ( const QUrl &  url)
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 93 of file networkdiskcache.cpp.

QIODevice * LeechCraft::Util::NetworkDiskCache::prepare ( const QNetworkCacheMetaData &  metadata)
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 99 of file networkdiskcache.cpp.

bool LeechCraft::Util::NetworkDiskCache::remove ( const QUrl &  url)
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 108 of file networkdiskcache.cpp.

void LeechCraft::Util::NetworkDiskCache::updateMetaData ( const QNetworkCacheMetaData &  metaData)
virtual

Reimplemented from QNetworkDiskCache.

Definition at line 116 of file networkdiskcache.cpp.


The documentation for this class was generated from the following files: