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  m_sURL(),
21  m_aPropertiesNames()
22  {
23  }
24 
25  PropertyNames::PropertyNames( const OUString& rURL ) :
26  m_nStaleTime( 0 ),
27  m_sURL( rURL ),
28  m_aPropertiesNames()
29  {
30  }
31 
32  //PropertyNamesCache implementation
33 
35  {
36  }
37 
39  {
40  }
41 
42  bool PropertyNamesCache::getCachedPropertyNames( const OUString& rURL, PropertyNames& rCacheElement )
43  {
44  // search the URL in the static map
45  osl::MutexGuard aGuard( m_aMutex );
46  PropNameCache::const_iterator it = m_aTheCache.find( rURL );
47  if ( it == m_aTheCache.end() )
48  return false;
49  else
50  {
51  // check if the element is stale, before restoring
52  TimeValue t1;
53  osl_getSystemTime( &t1 );
54  if ( (*it).second.getStaleTime() < t1.Seconds )
55  {
56  // if stale, remove from cache, do not restore
57  m_aTheCache.erase( it );
58  return false;
59  // return false instead
60  }
61  rCacheElement = (*it).second;
62  return true;
63  }
64  }
65 
66  void PropertyNamesCache::removeCachedPropertyNames( const OUString& rURL )
67  {
68  osl::MutexGuard aGuard( m_aMutex );
69  PropNameCache::const_iterator it = m_aTheCache.find( rURL );
70  if ( it != m_aTheCache.end() )
71  {
72  m_aTheCache.erase( it );
73  }
74  }
75 
77  {
78  osl::MutexGuard aGuard( m_aMutex );
79  OUString aURL( rCacheElement.getURL() );
80  TimeValue t1;
81  osl_getSystemTime( &t1 );
82  rCacheElement.setStaleTime( t1.Seconds + 10 );
83 
84  m_aTheCache[ aURL ] = rCacheElement;
85  }
86 
87 }
88 
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
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)