LibreOffice Module ucb (master)  1
PropfindCache.hxx
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 #pragma once
11 
12 #include <sal/types.h>
13 #include <rtl/ustring.hxx>
14 #include <mutex>
15 #include <map>
16 #include <vector>
17 
18 #include "DAVResource.hxx"
19 
20 namespace webdav_ucp
21 {
22  // A property names cache mechanism, URL driven.
23  // It is used to cache the property names received
24  // from the WebDAV server, to minimize the need of
25  // net transactions (e.g. PROPFIND).
26  // The cache lifetime should be short
27  // just to remove the annoying slowness when
28  // typing text or moving cursor around when the
29  // net link is slow.
30 
31  // Define the properties cache element
32  class PropertyNames final
33  {
35  sal_uInt32 m_nStaleTime;
36  OUString m_sURL;
37  // the property name list received from WebDAV server
38  std::vector< DAVResourceInfo > m_aPropertiesNames;
39 
40  public:
41  PropertyNames();
42  explicit PropertyNames( const OUString& rURL );
43 
44  sal_uInt32 getStaleTime() const { return m_nStaleTime; };
45  void setStaleTime( const sal_uInt32 nStaleTime ) { m_nStaleTime = nStaleTime; };
46 
47  OUString& getURL() { return m_sURL; };
48 
49  const std::vector< DAVResourceInfo >& getPropertiesNames() const { return m_aPropertiesNames; };
50  void setPropertiesNames( std::vector< DAVResourceInfo >&& aPropertiesNames ) { m_aPropertiesNames = std::move(aPropertiesNames); };
51  };
52 
53  // Define the PropertyNames cache
54  // TODO: the OUString key element in std::map needs to be changed with a URI representation
55  // with a specific compare (std::less) implementation, this last one implementing
56  // as suggested in <https://tools.ietf.org/html/rfc3986#section-6>.
57  // To find by URI and not by string equality.
58  typedef std::map< OUString, PropertyNames,
59  std::less< OUString > >PropNameCache;
60 
61  class PropertyNamesCache final
62  {
63  PropNameCache m_aTheCache;
64  std::mutex m_aMutex;
65 
66  public:
69 
70  bool getCachedPropertyNames( const OUString& URL, PropertyNames& rCacheElement );
71  void removeCachedPropertyNames( const OUString& URL );
72  void addCachePropertyNames( PropertyNames& rCacheElement );
73  };
74 
75 }
76 
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void setStaleTime(const sal_uInt32 nStaleTime)
sal_uInt32 m_nStaleTime
target time when this element becomes stale
std::vector< DAVResourceInfo > m_aPropertiesNames
sal_uInt32 getStaleTime() const
void addCachePropertyNames(PropertyNames &rCacheElement)
const std::vector< DAVResourceInfo > & getPropertiesNames() const
void setPropertiesNames(std::vector< DAVResourceInfo > &&aPropertiesNames)
std::map< OUString, PropertyNames, std::less< OUString > > PropNameCache
void removeCachedPropertyNames(const OUString &URL)
bool getCachedPropertyNames(const OUString &URL, PropertyNames &rCacheElement)