Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / webdav-curl / PropfindCache.cxx
blobda8499e1526d81cff7628ab4003605d26d528b0b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <osl/time.h>
12 #include <utility>
13 #include "PropfindCache.hxx"
15 namespace http_dav_ucp
18 // PropertyNames implementation
20 PropertyNames::PropertyNames() :
21 m_nStaleTime( 0 ),
22 m_sURL(),
23 m_aPropertiesNames()
27 PropertyNames::PropertyNames( OUString aURL ) :
28 m_nStaleTime( 0 ),
29 m_sURL(std::move( aURL )),
30 m_aPropertiesNames()
34 //PropertyNamesCache implementation
36 PropertyNamesCache::PropertyNamesCache()
40 PropertyNamesCache::~PropertyNamesCache()
44 bool PropertyNamesCache::getCachedPropertyNames( const OUString& rURL, PropertyNames& rCacheElement )
46 // search the URL in the static map
47 std::unique_lock aGuard( m_aMutex );
48 PropNameCache::const_iterator it;
49 it = m_aTheCache.find( rURL );
50 if ( it == m_aTheCache.end() )
51 return false;
52 else
54 // check if the element is stale, before restoring
55 TimeValue t1;
56 osl_getSystemTime( &t1 );
57 if ( (*it).second.getStaleTime() < t1.Seconds )
59 // if stale, remove from cache, do not restore
60 m_aTheCache.erase( it );
61 return false;
62 // return false instead
64 rCacheElement = (*it).second;
65 return true;
69 void PropertyNamesCache::removeCachedPropertyNames( const OUString& rURL )
71 std::unique_lock aGuard( m_aMutex );
72 PropNameCache::const_iterator it;
73 it = m_aTheCache.find( rURL );
74 if ( it != m_aTheCache.end() )
76 m_aTheCache.erase( it );
80 void PropertyNamesCache::addCachePropertyNames( PropertyNames& rCacheElement, const sal_uInt32 nLifeTime )
82 std::unique_lock aGuard( m_aMutex );
83 OUString aURL( rCacheElement.getURL() );
84 TimeValue t1;
85 osl_getSystemTime( &t1 );
86 rCacheElement.setStaleTime( t1.Seconds + nLifeTime );
88 m_aTheCache[ aURL ] = rCacheElement;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */