|  | Home · All Classes · Modules

# QNetworkDiskCache Class Reference
[QtNetwork module]

The QNetworkDiskCache class provides a very basic disk cache. More...

Inherits QAbstractNetworkCache.

### Methods

- __init__ (self, QObject parent = None)
- QString cacheDirectory (self)
- long cacheSize (self)
- clear (self)
- QIODevice data (self, QUrl url)
- long expire (self)
- QNetworkCacheMetaData fileMetaData (self, QString fileName)
- insert (self, QIODevice device)
- long maximumCacheSize (self)
- QNetworkCacheMetaData metaData (self, QUrl url)
- QIODevice prepare (self, QNetworkCacheMetaData metaData)
- bool remove (self, QUrl url)
- setCacheDirectory (self, QString cacheDir)
- setMaximumCacheSize (self, long size)
- updateMetaData (self, QNetworkCacheMetaData metaData)

## Detailed Description

The QNetworkDiskCache class provides a very basic disk cache.

QNetworkDiskCache stores each url in its own file inside of the cacheDirectory using QDataStream. Files with a text MimeType are compressed using qCompress. Each cache file starts with "cache_" and ends in ".cache". Data is written to disk only in insert() and updateMetaData().

Currently you can not share the same cache files with more then one disk cache.

QNetworkDiskCache by default limits the amount of space that the cache will use on the system to 50MB.

Note you have to set the cache directory before it will work.

## Method Documentation

### QNetworkDiskCache.__init__ (self, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Creates a new disk cache. The parent argument is passed to QAbstractNetworkCache's constructor.

### QString QNetworkDiskCache.cacheDirectory (self)

Returns the location where cached files will be stored.

See also setCacheDirectory().

### long QNetworkDiskCache.cacheSize (self)

### QNetworkDiskCache.clear (self)

This method is also a Qt slot with the C++ signature `void clear()`.

### QIODevice QNetworkDiskCache.data (self, QUrl url)

### long QNetworkDiskCache.expire (self)

Cleans the cache so that its size is under the maximum cache size. Returns the current size of the cache.

When the current size of the cache is greater then the maximumCacheSize() older cache files are removed until the total size is less then 90% of maximumCacheSize() starting with the oldest ones first using the file creation date to determine how old a cache file is.

Subclasses can reimplement this function to change the order that cache files are removed taking into account information in the application knows about that QNetworkDiskCache does not, for example the number of times a cache is accessed.

Note: cacheSize() calls expire if the current cache size is unknown.

See also maximumCacheSize() and fileMetaData().

### QNetworkCacheMetaData QNetworkDiskCache.fileMetaData (self, QString fileName)

Returns the QNetworkCacheMetaData for the cache file fileName.

If fileName is not a cache file QNetworkCacheMetaData will be invalid.

### QNetworkDiskCache.insert (self, QIODevice device)

### long QNetworkDiskCache.maximumCacheSize (self)

Returns the current maximum size for the disk cache.

See also setMaximumCacheSize().

### QNetworkCacheMetaData QNetworkDiskCache.metaData (self, QUrl url)

### QIODevice QNetworkDiskCache.prepare (self, QNetworkCacheMetaData metaData)

### bool QNetworkDiskCache.remove (self, QUrl url)

### QNetworkDiskCache.setCacheDirectory (self, QString cacheDir)

Sets the directory where cached files will be stored to cacheDir

QNetworkDiskCache will create this directory if it does not exists.

Prepared cache items will be stored in the new cache directory when they are inserted.

See also cacheDirectory() and QDesktopServices.CacheLocation.

### QNetworkDiskCache.setMaximumCacheSize (self, long size)

Sets the maximum size of the disk cache to be size.

If the new size is smaller then the current cache size then the cache will call expire().

See also maximumCacheSize().

### QNetworkDiskCache.updateMetaData (self, QNetworkCacheMetaData metaData)