com.trolltech.qt.network
Class QNetworkDiskCache

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.core.QObject
                  extended by com.trolltech.qt.network.QAbstractNetworkCache
                      extended by com.trolltech.qt.network.QNetworkDiskCache
All Implemented Interfaces:
QtJambiInterface

public class QNetworkDiskCache
extends QAbstractNetworkCache

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.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QNetworkDiskCache()
          Creates a new disk cache.
QNetworkDiskCache(QObject parent)
          Creates a new disk cache.
 
Method Summary
 java.lang.String cacheDirectory()
          Returns the location where cached files will be stored.
protected  long expire()
          Cleans the cache so that its size is under the maximum cache size.
 QNetworkCacheMetaData fileMetaData(java.lang.String fileName)
          Returns the QNetworkCacheMetaData for the cache file fileName.
 long maximumCacheSize()
          Returns the current maximum size for the disk cache.
 void setCacheDirectory(java.lang.String cacheDir)
          Sets the directory where cached files will be stored to cacheDir
 void setMaximumCacheSize(long size)
          Sets the maximum size of the disk cache to be size.
 
Methods inherited from class com.trolltech.qt.network.QAbstractNetworkCache
cacheSize, clear, data, insert, metaData, prepare, remove, updateMetaData
 
Methods inherited from class com.trolltech.qt.core.QObject
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QNetworkDiskCache

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


QNetworkDiskCache

public QNetworkDiskCache(QObject parent)
Creates a new disk cache. The parent argument is passed to QAbstractNetworkCache's constructor.

Method Detail

cacheDirectory

public final java.lang.String cacheDirectory()
Returns the location where cached files will be stored.

See also:
setCacheDirectory().


fileMetaData

public final QNetworkCacheMetaData fileMetaData(java.lang.String fileName)
Returns the QNetworkCacheMetaData for the cache file fileName.

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


maximumCacheSize

public final long maximumCacheSize()
Returns the current maximum size for the disk cache.

See also:
setMaximumCacheSize().


setCacheDirectory

public final void setCacheDirectory(java.lang.String 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 .


setMaximumCacheSize

public final void setMaximumCacheSize(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().


expire

protected long expire()
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().