Marble
13 #include <QDirIterator>
14 #include <QDataStream>
23 DiscCache::DiscCache(
const QString &cacheDirectory )
24 : m_CacheDirectory( cacheDirectory ),
25 m_CacheLimit( 300 * 1024 * 1024 ),
26 m_CurrentCacheSize( 0 )
28 Q_ASSERT( !m_CacheDirectory.isEmpty() &&
"Passed empty cache directory!" );
30 QFile file( indexFileName( m_CacheDirectory ) );
32 if ( file.exists() ) {
38 s >> m_CurrentCacheSize;
42 qWarning(
"Unable to open cache directory %s", qPrintable( m_CacheDirectory ) );
47 DiscCache::~DiscCache()
49 QFile file( indexFileName( m_CacheDirectory ) );
56 s << m_CurrentCacheSize;
63 quint64 DiscCache::cacheLimit()
const
68 void DiscCache::clear()
73 while ( it.hasNext() ) {
76 if ( it.fileName() == indexFileName( m_CacheDirectory ) )
86 m_CurrentCacheSize = 0;
89 bool DiscCache::exists(
const QString &key )
const
91 return m_Entries.contains( key );
97 if ( !m_Entries.contains( key ) )
101 QFile file( keyToFileName( key ) );
103 data = file.readAll();
115 QFile file( keyToFileName( key ) );
120 if ( m_Entries.contains( key ) )
121 m_CurrentCacheSize -= m_Entries.value( key ).second;
130 m_CurrentCacheSize += data.
length();
137 void DiscCache::remove(
const QString &key )
140 if ( !m_Entries.contains( key ) )
149 m_CurrentCacheSize -= m_Entries.value( key ).second;
152 m_Entries.remove( key );
155 void DiscCache::setCacheLimit( quint64 n )
167 return m_CacheDirectory +
QLatin1Char(
'/') + fileName;
170 void DiscCache::cleanup()
173 quint64 fivePercent = quint64( m_CacheLimit * 0.05 );
175 while ( m_CurrentCacheSize > (m_CacheLimit - fivePercent) ) {
180 while ( it.hasNext() ) {
183 if ( it.value().first < oldestDate ) {
184 oldestDate = it.value().first;
185 oldestKey = it.key();
QDateTime currentDateTime()
bool isEmpty() const const
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:50:18 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.