LibreOffice Module ucb (master)  1
PropfindCache.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <osl/time.h>
11 #include "PropfindCache.hxx"
12 
13 namespace webdav_ucp
14 {
15 
16  // PropertyNames implementation
17 
19  m_nStaleTime( 0 )
20  {
21  }
22 
23  PropertyNames::PropertyNames( const OUString& rURL ) :
24  m_nStaleTime( 0 ),
25  m_sURL( rURL )
26  {
27  }
28 
29  //PropertyNamesCache implementation
30 
32  {
33  }
34 
36  {
37  }
38 
39  bool PropertyNamesCache::getCachedPropertyNames( const OUString& rURL, PropertyNames& rCacheElement )
40  {
41  // search the URL in the static map
42  std::scoped_lock aGuard( m_aMutex );
43  PropNameCache::const_iterator it = m_aTheCache.find( rURL );
44  if ( it == m_aTheCache.end() )
45  return false;
46  else
47  {
48  // check if the element is stale, before restoring
49  TimeValue t1;
50  osl_getSystemTime( &t1 );
51  if ( (*it).second.getStaleTime() < t1.Seconds )
52  {
53  // if stale, remove from cache, do not restore
54  m_aTheCache.erase( it );
55  return false;
56  // return false instead
57  }
58  rCacheElement = (*it).second;
59  return true;
60  }
61  }
62 
63  void PropertyNamesCache::removeCachedPropertyNames( const OUString& rURL )
64  {
65  std::scoped_lock aGuard( m_aMutex );
66  PropNameCache::const_iterator it = m_aTheCache.find( rURL );
67  if ( it != m_aTheCache.end() )
68  {
69  m_aTheCache.erase( it );
70  }
71  }
72 
74  {
75  std::scoped_lock aGuard( m_aMutex );
76  OUString aURL( rCacheElement.getURL() );
77  TimeValue t1;
78  osl_getSystemTime( &t1 );
79  rCacheElement.setStaleTime( t1.Seconds + 10 );
80 
81  m_aTheCache[ aURL ] = rCacheElement;
82  }
83 
84 }
85 
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
URL aURL
void setStaleTime(const sal_uInt32 nStaleTime)
OUString m_sURL
void addCachePropertyNames(PropertyNames &rCacheElement)
void removeCachedPropertyNames(const OUString &URL)
bool getCachedPropertyNames(const OUString &URL, PropertyNames &rCacheElement)