1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
13 #include "PropfindCache.hxx"
15 namespace http_dav_ucp
18 // PropertyNames implementation
20 PropertyNames::PropertyNames() :
27 PropertyNames::PropertyNames( OUString aURL
) :
29 m_sURL(std::move( aURL
)),
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() )
54 // check if the element is stale, before restoring
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
);
62 // return false instead
64 rCacheElement
= (*it
).second
;
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() );
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: */