File indexing completed on 2025-01-05 03:59:34

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 #include <klocalizedstring.h>
0014 
0015 using namespace Marble;
0016 
0017 CacheStoragePolicy::CacheStoragePolicy( const QString &cacheDirectory )
0018     : m_cache( cacheDirectory )
0019 {
0020     if ( ! QDir( cacheDirectory ).exists() )
0021         QDir::root().mkpath( cacheDirectory );
0022 }
0023 
0024 CacheStoragePolicy::~CacheStoragePolicy()
0025 {
0026 }
0027 
0028 bool CacheStoragePolicy::fileExists( const QString &fileName ) const
0029 {
0030     return m_cache.exists( fileName );
0031 }
0032 
0033 bool CacheStoragePolicy::updateFile( const QString &fileName, const QByteArray &data )
0034 {
0035     if ( !m_cache.insert( fileName, data ) ) {
0036         m_errorMsg = i18n("Unable to insert data into cache");
0037         return false;
0038     }
0039 
0040     return true;
0041 }
0042 
0043 void CacheStoragePolicy::clearCache()
0044 {
0045     m_cache.clear();
0046 }
0047 
0048 QString CacheStoragePolicy::lastErrorMessage() const
0049 {
0050     return m_errorMsg;
0051 }
0052 
0053 QByteArray CacheStoragePolicy::data( const QString &fileName )
0054 {
0055     QByteArray data;
0056     m_cache.find( fileName, data );
0057 
0058     return data;
0059 }
0060 
0061 void CacheStoragePolicy::setCacheLimit( quint64 bytes )
0062 {
0063     m_cache.setCacheLimit( bytes );
0064 }
0065 
0066 quint64 CacheStoragePolicy::cacheLimit() const
0067 {
0068     return m_cache.cacheLimit();
0069 }
0070 
0071 #include "moc_CacheStoragePolicy.cpp"