|
| 1 | +// Copyright 2019 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_CACHE_POLICY_H_ |
| 16 | +#define FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_CACHE_POLICY_H_ |
| 17 | + |
| 18 | +#include <cstdint> |
| 19 | + |
| 20 | +namespace firebase { |
| 21 | +namespace database { |
| 22 | +namespace internal { |
| 23 | + |
| 24 | +class CachePolicy { |
| 25 | + public: |
| 26 | + virtual ~CachePolicy(); |
| 27 | + |
| 28 | + virtual bool ShouldPrune(uint64_t current_size_bytes, |
| 29 | + uint64_t count_of_prunable_queries) const = 0; |
| 30 | + |
| 31 | + virtual bool ShouldCheckCacheSize( |
| 32 | + uint64_t serverUpdatesSinceLastCheck) const = 0; |
| 33 | + |
| 34 | + virtual double GetPercentOfQueriesToPruneAtOnce() const = 0; |
| 35 | + |
| 36 | + virtual uint64_t GetMaxNumberOfQueriesToKeep() const = 0; |
| 37 | +}; |
| 38 | + |
| 39 | +class LRUCachePolicy : public CachePolicy { |
| 40 | + public: |
| 41 | + explicit LRUCachePolicy(uint64_t max_size_bytes); |
| 42 | + |
| 43 | + ~LRUCachePolicy() override; |
| 44 | + |
| 45 | + bool ShouldPrune(uint64_t current_size_bytes, |
| 46 | + uint64_t count_of_prunable_queries) const override; |
| 47 | + |
| 48 | + bool ShouldCheckCacheSize( |
| 49 | + uint64_t server_updates_since_last_check) const override; |
| 50 | + |
| 51 | + double GetPercentOfQueriesToPruneAtOnce() const override; |
| 52 | + |
| 53 | + uint64_t GetMaxNumberOfQueriesToKeep() const override; |
| 54 | + |
| 55 | + private: |
| 56 | + const uint64_t max_size_bytes_; |
| 57 | +}; |
| 58 | + |
| 59 | +} // namespace internal |
| 60 | +} // namespace database |
| 61 | +} // namespace firebase |
| 62 | + |
| 63 | +#endif // FIREBASE_DATABASE_CLIENT_CPP_SRC_DESKTOP_CORE_CACHE_POLICY_H_ |
0 commit comments