File indexing completed on 2024-05-26 05:14:08

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadicore_export.h"
0010 
0011 #include <QSharedDataPointer>
0012 #include <QStringList>
0013 
0014 namespace Akonadi
0015 {
0016 class CachePolicyPrivate;
0017 
0018 /**
0019  * @short Represents the caching policy for a collection.
0020  *
0021  * There is one cache policy per collection. It can either specify that all
0022  * properties of the policy of the parent collection will be inherited (the
0023  * default) or specify the following values:
0024  *
0025  * - The item parts that should be permanently kept locally and are downloaded
0026  *   during a collection sync (e.g. full mail vs. just the headers).
0027  * - A minimum time for which non-permanently cached item parts have to be kept
0028  *   (0 - infinity).
0029  * - Whether or not a collection sync is triggered on demand, i.e. as soon
0030  *   as it is accessed by a client.
0031  * - An optional time interval for regular collection sync (aka interval
0032  *   mail check).
0033  *
0034  * Syncing means fetching updates from the Akonadi database. The cache policy
0035  * does not affect updates of the Akonadi database from the backend, since
0036  * backend updates will normally immediately trigger the resource to update the
0037  * Akonadi database.
0038  *
0039  * The cache policy applies only to reading from the collection. Writing to the
0040  * collection is independent of cache policy - all updates are written to the
0041  * backend as soon as the resource can schedule this.
0042  *
0043  * @code
0044  *
0045  * Akonadi::CachePolicy policy;
0046  * policy.setCacheTimeout( 30 );
0047  * policy.setIntervalCheckTime( 20 );
0048  *
0049  * Akonadi::Collection collection = ...
0050  * collection.setCachePolicy( policy );
0051  *
0052  * @endcode
0053  *
0054  * @todo Do we also need a size limit for the cache as well?
0055  * @todo on a POP3 account, is should not be possible to change locally cached parts, find a solution for that
0056  *
0057  * @author Volker Krause <vkrause@kde.org>
0058  */
0059 class AKONADICORE_EXPORT CachePolicy
0060 {
0061 public:
0062     /**
0063      * Creates an empty cache policy.
0064      */
0065     CachePolicy();
0066 
0067     /**
0068      * Creates a cache policy from an @p other cache policy.
0069      */
0070     CachePolicy(const CachePolicy &other);
0071 
0072     /**
0073      * Destroys the cache policy.
0074      */
0075     ~CachePolicy();
0076 
0077     /**
0078      * Returns whether it inherits cache policy from the parent collection.
0079      */
0080     bool inheritFromParent() const;
0081 
0082     /**
0083      * Sets whether the cache policy should be inherited from the parent collection.
0084      */
0085     void setInheritFromParent(bool inherit);
0086 
0087     /**
0088      * Returns the parts to permanently cache locally.
0089      */
0090     [[nodiscard]] QStringList localParts() const;
0091 
0092     /**
0093      * Specifies the parts to permanently cache locally.
0094      */
0095     void setLocalParts(const QStringList &parts);
0096 
0097     /**
0098      * Returns the cache timeout for non-permanently cached parts in minutes;
0099      * -1 means indefinitely.
0100      */
0101     [[nodiscard]] int cacheTimeout() const;
0102 
0103     /**
0104      * Sets cache timeout for non-permanently cached parts.
0105      * @param timeout Timeout in minutes, -1 for indefinitely.
0106      */
0107     void setCacheTimeout(int timeout);
0108 
0109     /**
0110      * Returns the interval check time in minutes, -1 for never.
0111      */
0112     [[nodiscard]] int intervalCheckTime() const;
0113 
0114     /**
0115      * Sets interval check time.
0116      * @param time Check time interval in minutes, -1 for never.
0117      */
0118     void setIntervalCheckTime(int time);
0119 
0120     /**
0121      * Returns whether the collection will be synced automatically when necessary,
0122      * i.e. as soon as it is accessed by a client.
0123      */
0124     [[nodiscard]] bool syncOnDemand() const;
0125 
0126     /**
0127      * Sets whether the collection shall be synced automatically when necessary,
0128      * i.e. as soon as it is accessed by a client.
0129      * @param enable If @c true the collection is synced.
0130      */
0131     void setSyncOnDemand(bool enable);
0132 
0133     /**
0134      * @internal.
0135      * @param other other cache policy
0136      */
0137     CachePolicy &operator=(const CachePolicy &other);
0138 
0139     /**
0140      * @internal
0141      * @param other other cache policy
0142      */
0143     [[nodiscard]] bool operator==(const CachePolicy &other) const;
0144 
0145 private:
0146     /// @cond PRIVATE
0147     QSharedDataPointer<CachePolicyPrivate> d;
0148     /// @endcond
0149 };
0150 
0151 }
0152 
0153 /**
0154  * Allows a cache policy to be output for debugging purposes.
0155  */
0156 AKONADICORE_EXPORT QDebug operator<<(QDebug, const Akonadi::CachePolicy &);