File indexing completed on 2024-04-28 11:30:47

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0004 //
0005 
0006 
0007 // Own
0008 #include "CacheStoragePolicy.h"
0009 
0010 // Qt
0011 #include <QDir>
0012 
0013 using namespace Marble;
0014 
0015 CacheStoragePolicy::CacheStoragePolicy( const QString &cacheDirectory )
0016     : m_cache( cacheDirectory )
0017 {
0018     if ( ! QDir( cacheDirectory ).exists() ) 
0019         QDir::root().mkpath( cacheDirectory );
0020 }
0021 
0022 CacheStoragePolicy::~CacheStoragePolicy()
0023 {
0024 }
0025 
0026 bool CacheStoragePolicy::fileExists( const QString &fileName ) const
0027 {
0028     return m_cache.exists( fileName );
0029 }
0030 
0031 bool CacheStoragePolicy::updateFile( const QString &fileName, const QByteArray &data )
0032 {
0033     if ( !m_cache.insert( fileName, data ) ) {
0034         m_errorMsg = QObject::tr("Unable to insert data into cache");
0035         return false;
0036     }
0037 
0038     return true;
0039 }
0040 
0041 void CacheStoragePolicy::clearCache()
0042 {
0043     m_cache.clear();
0044 }
0045 
0046 QString CacheStoragePolicy::lastErrorMessage() const
0047 {
0048     return m_errorMsg;
0049 }
0050 
0051 QByteArray CacheStoragePolicy::data( const QString &fileName )
0052 {
0053     QByteArray data;
0054     m_cache.find( fileName, data );
0055 
0056     return data;
0057 }
0058 
0059 void CacheStoragePolicy::setCacheLimit( quint64 bytes )
0060 {
0061     m_cache.setCacheLimit( bytes );
0062 }
0063 
0064 quint64 CacheStoragePolicy::cacheLimit() const
0065 {
0066     return m_cache.cacheLimit();
0067 }
0068 
0069 #include "moc_CacheStoragePolicy.cpp"