Skip to content

Commit 26e9896

Browse files
committed
LRU GC compiles
1 parent 12086e0 commit 26e9896

File tree

6 files changed

+136
-38
lines changed

6 files changed

+136
-38
lines changed

firestore/src/common/local_cache_settings.cc

+40-9
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,65 @@ PersistentCacheSettings::~PersistentCacheSettings() {
3838
}
3939

4040
PersistentCacheSettings::PersistentCacheSettings(
41-
const PersistentCacheSettingsInternal& other) {
42-
settings_internal_ = std::make_unique<PersistentCacheSettingsInternal>(other);
41+
const PersistentCacheSettings& other) {
42+
settings_internal_ = std::make_unique<PersistentCacheSettingsInternal>(
43+
*other.settings_internal_);
4344
}
4445

4546
PersistentCacheSettings PersistentCacheSettings::WithSizeBytes(
4647
int64_t size) const {
47-
return {PersistentCacheSettingsInternal{
48-
settings_internal_->core_settings().WithSizeBytes(size)}};
48+
PersistentCacheSettings new_settings{*this};
49+
new_settings.settings_internal_->set_core_settings(
50+
new_settings.settings_internal_->core_settings().WithSizeBytes(size));
51+
return new_settings;
4952
}
5053

5154
const CoreCacheSettings& PersistentCacheSettings::core_cache_settings() const {
5255
return settings_internal_->core_settings();
5356
}
5457

58+
MemoryEagerGCSettings MemoryEagerGCSettings::Create() { return {}; }
59+
60+
MemoryEagerGCSettings::MemoryEagerGCSettings() {
61+
settings_internal_ = std::make_unique<MemoryEagerGCSettingsInternal>(
62+
CoreMemoryEagerGcSettings{});
63+
}
64+
65+
MemoryEagerGCSettings::~MemoryEagerGCSettings() { settings_internal_.reset(); }
66+
67+
MemoryLruGCSettings MemoryLruGCSettings::Create() { return {}; }
68+
69+
MemoryLruGCSettings::MemoryLruGCSettings() {
70+
settings_internal_ =
71+
std::make_unique<MemoryLruGCSettingsInternal>(CoreMemoryLruGcSettings{});
72+
}
73+
74+
MemoryLruGCSettings::MemoryLruGCSettings(
75+
const MemoryLruGCSettingsInternal& other) {
76+
settings_internal_ = std::make_unique<MemoryLruGCSettingsInternal>(other);
77+
}
78+
79+
MemoryLruGCSettings::~MemoryLruGCSettings() { settings_internal_.reset(); }
80+
81+
MemoryLruGCSettings MemoryLruGCSettings::WithSizeBytes(int64_t size) {
82+
return {MemoryLruGCSettingsInternal{
83+
settings_internal_->core_settings().WithSizeBytes(size)}};
84+
}
85+
5586
MemoryCacheSettings MemoryCacheSettings::Create() { return {}; }
5687

5788
MemoryCacheSettings::MemoryCacheSettings() {
5889
settings_internal_ =
5990
std::make_unique<MemoryCacheSettingsInternal>(CoreMemorySettings{});
6091
}
6192

62-
MemoryCacheSettings::~MemoryCacheSettings() { settings_internal_.reset(); }
63-
64-
MemoryCacheSettings::MemoryCacheSettings(
65-
const MemoryCacheSettingsInternal& other) {
66-
settings_internal_ = std::make_unique<MemoryCacheSettingsInternal>(other);
93+
MemoryCacheSettings::MemoryCacheSettings(const MemoryCacheSettings& other) {
94+
settings_internal_ =
95+
std::make_unique<MemoryCacheSettingsInternal>(*other.settings_internal_);
6796
}
6897

98+
MemoryCacheSettings::~MemoryCacheSettings() { settings_internal_.reset(); }
99+
69100
const CoreCacheSettings& MemoryCacheSettings::core_cache_settings() const {
70101
return settings_internal_->core_settings();
71102
}

firestore/src/common/settings.cc

+11-13
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,21 @@ void Settings::set_host(std::string host) { host_ = firebase::Move(host); }
5656

5757
void Settings::set_ssl_enabled(bool enabled) { ssl_enabled_ = enabled; }
5858

59-
std::shared_ptr<LocalCacheSettings> Settings::local_cache_settings() const {
59+
std::shared_ptr<LocalCacheSettings> Settings::local_cache_settings() {
6060
if (used_legacy_cache_settings_) {
6161
if (is_persistence_enabled()) {
62-
return std::make_shared<PersistentCacheSettings>(
63-
*PersistentCacheSettings::Create()
64-
.WithSizeBytes(cache_size_bytes())
65-
.settings_internal_);
62+
local_cache_settings_ = std::make_shared<PersistentCacheSettings>(
63+
PersistentCacheSettings::Create().WithSizeBytes(cache_size_bytes()));
6664
} else {
67-
return std::make_shared<MemoryCacheSettings>(
68-
*MemoryCacheSettings::Create().settings_internal_);
65+
local_cache_settings_ =
66+
std::make_shared<MemoryCacheSettings>(MemoryCacheSettings::Create());
6967
}
70-
} else if (local_cache_settings_ != nullptr) {
71-
return local_cache_settings_;
68+
} else if (local_cache_settings_ == nullptr) {
69+
local_cache_settings_ = std::make_shared<PersistentCacheSettings>(
70+
PersistentCacheSettings::Create());
7271
}
7372

74-
return std::make_shared<PersistentCacheSettings>(
75-
*PersistentCacheSettings::Create().settings_internal_);
73+
return local_cache_settings_;
7674
}
7775

7876
void Settings::set_local_cache_settings(const LocalCacheSettings& cache) {
@@ -84,10 +82,10 @@ void Settings::set_local_cache_settings(const LocalCacheSettings& cache) {
8482

8583
if (cache.kind() == api::LocalCacheSettings::Kind::kPersistent) {
8684
local_cache_settings_ = std::make_shared<PersistentCacheSettings>(
87-
*static_cast<const PersistentCacheSettings&>(cache).settings_internal_);
85+
static_cast<const PersistentCacheSettings&>(cache));
8886
} else {
8987
local_cache_settings_ = std::make_shared<MemoryCacheSettings>(
90-
*static_cast<const MemoryCacheSettings&>(cache).settings_internal_);
88+
static_cast<const MemoryCacheSettings&>(cache));
9189
}
9290
}
9391

firestore/src/include/firebase/firestore/local_cache_settings.h

+49-14
Original file line numberDiff line numberDiff line change
@@ -21,66 +21,101 @@
2121
#include <memory>
2222

2323
#include "Firestore/core/src/api/settings.h"
24-
#include "firestore/src/main/firestore_main.h"
24+
#include "firestore/src/include/firebase/firestore/settings.h"
25+
#include "firestore/src/main/local_cache_settings_main.h"
2526

2627
namespace firebase {
2728
namespace firestore {
2829

2930
using CoreCacheSettings = api::LocalCacheSettings;
30-
using CoreMemorySettings = api::MemoryCacheSettings;
31-
using CorePersistentSettings = api::PersistentCacheSettings;
3231

33-
class Settings;
3432
class PersistentCacheSettingsInternal;
3533
class MemoryCacheSettingsInternal;
3634

3735
class LocalCacheSettings {
3836
public:
39-
virtual api::LocalCacheSettings::Kind kind() const = 0;
4037
virtual ~LocalCacheSettings() = default;
4138

4239
private:
4340
friend class FirestoreInternal;
41+
friend class Settings;
4442

43+
virtual api::LocalCacheSettings::Kind kind() const = 0;
4544
virtual const CoreCacheSettings& core_cache_settings() const = 0;
4645
};
4746

4847
class PersistentCacheSettings final : public LocalCacheSettings {
4948
public:
5049
static PersistentCacheSettings Create();
50+
51+
PersistentCacheSettings(const PersistentCacheSettings& other);
5152
~PersistentCacheSettings();
52-
PersistentCacheSettings(const PersistentCacheSettingsInternal& other);
5353

5454
PersistentCacheSettings WithSizeBytes(int64_t size) const;
55-
api::LocalCacheSettings::Kind kind() const override {
56-
return api::LocalCacheSettings::Kind::kPersistent;
57-
}
5855

5956
private:
6057
friend class Settings;
6158

6259
PersistentCacheSettings();
60+
PersistentCacheSettings(const PersistentCacheSettingsInternal& other);
61+
62+
api::LocalCacheSettings::Kind kind() const override {
63+
return api::LocalCacheSettings::Kind::kPersistent;
64+
}
6365

6466
const CoreCacheSettings& core_cache_settings() const override;
6567

6668
std::unique_ptr<PersistentCacheSettingsInternal> settings_internal_;
6769
};
6870

71+
class MemoryGarbageCollectorSettings {
72+
public:
73+
virtual ~MemoryGarbageCollectorSettings() = default;
74+
75+
private:
76+
};
77+
78+
class MemoryEagerGCSettings final : MemoryGarbageCollectorSettings {
79+
static MemoryEagerGCSettings Create();
80+
~MemoryEagerGCSettings();
81+
82+
private:
83+
MemoryEagerGCSettings();
84+
85+
std::unique_ptr<MemoryEagerGCSettingsInternal> settings_internal_;
86+
};
87+
88+
class MemoryLruGCSettings final : MemoryGarbageCollectorSettings {
89+
static MemoryLruGCSettings Create();
90+
~MemoryLruGCSettings();
91+
MemoryLruGCSettings WithSizeBytes(int64_t size);
92+
93+
private:
94+
MemoryLruGCSettings();
95+
MemoryLruGCSettings(const MemoryLruGCSettingsInternal& other);
96+
97+
std::unique_ptr<MemoryLruGCSettingsInternal> settings_internal_;
98+
};
99+
69100
class MemoryCacheSettings final : public LocalCacheSettings {
70101
public:
71102
static MemoryCacheSettings Create();
103+
MemoryCacheSettings(const MemoryCacheSettings& other);
72104
~MemoryCacheSettings();
73105

74-
api::LocalCacheSettings::Kind kind() const override {
75-
return api::LocalCacheSettings::Kind::kMemory;
76-
}
77-
78-
MemoryCacheSettings(const MemoryCacheSettingsInternal& other);
106+
MemoryCacheSettings WithGarbageCollectorSettings(
107+
const MemoryGarbageCollectorSettings& settings);
79108

80109
private:
81110
friend class Settings;
82111

83112
MemoryCacheSettings();
113+
MemoryCacheSettings(const MemoryCacheSettingsInternal& other);
114+
115+
api::LocalCacheSettings::Kind kind() const override {
116+
return api::LocalCacheSettings::Kind::kMemory;
117+
}
118+
84119
const CoreCacheSettings& core_cache_settings() const override;
85120

86121
std::unique_ptr<MemoryCacheSettingsInternal> settings_internal_;

firestore/src/include/firebase/firestore/settings.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef FIREBASE_FIRESTORE_SRC_INCLUDE_FIREBASE_FIRESTORE_SETTINGS_H_
1818
#define FIREBASE_FIRESTORE_SRC_INCLUDE_FIREBASE_FIRESTORE_SETTINGS_H_
1919

20-
#include "firebase/firestore/local_cache_settings.h"
2120
#if defined(__OBJC__)
2221
#include <dispatch/dispatch.h>
2322
#endif
@@ -138,7 +137,7 @@ class Settings final {
138137
*/
139138
void set_ssl_enabled(bool enabled);
140139

141-
std::shared_ptr<LocalCacheSettings> local_cache_settings() const;
140+
std::shared_ptr<LocalCacheSettings> local_cache_settings();
142141
void set_local_cache_settings(const LocalCacheSettings& cache);
143142

144143
/**

firestore/src/main/firestore_main.cc

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "firestore/src/common/macros.h"
4444
#include "firestore/src/common/util.h"
4545
#include "firestore/src/include/firebase/firestore.h"
46+
#include "firestore/src/include/firebase/firestore/local_cache_settings.h"
4647
#include "firestore/src/main/converter_main.h"
4748
#include "firestore/src/main/create_app_check_credentials_provider.h"
4849
#include "firestore/src/main/create_credentials_provider.h"

firestore/src/main/local_cache_settings_main.h

+34
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
namespace firebase {
2525
namespace firestore {
2626

27+
using CoreMemoryEagerGcSettings = api::MemoryEagerGcSettings;
28+
using CoreMemoryLruGcSettings = api::MemoryLruGcSettings;
2729
using CoreMemorySettings = api::MemoryCacheSettings;
2830
using CorePersistentSettings = api::PersistentCacheSettings;
2931

@@ -44,6 +46,38 @@ class PersistentCacheSettingsInternal final
4446
CorePersistentSettings settings_;
4547
};
4648

49+
class MemoryGarbageCollectorSettingsInternal {};
50+
51+
class MemoryEagerGCSettingsInternal final
52+
: public MemoryGarbageCollectorSettingsInternal {
53+
public:
54+
explicit MemoryEagerGCSettingsInternal(
55+
const CoreMemoryEagerGcSettings& core_settings)
56+
: settings_(std::move(core_settings)) {}
57+
const CoreMemoryEagerGcSettings& core_settings() { return settings_; }
58+
void set_core_settings(const CoreMemoryEagerGcSettings& settings) {
59+
settings_ = settings;
60+
}
61+
62+
private:
63+
CoreMemoryEagerGcSettings settings_;
64+
};
65+
66+
class MemoryLruGCSettingsInternal final
67+
: public MemoryGarbageCollectorSettingsInternal {
68+
public:
69+
explicit MemoryLruGCSettingsInternal(
70+
const CoreMemoryLruGcSettings& core_settings)
71+
: settings_(std::move(core_settings)) {}
72+
const CoreMemoryLruGcSettings& core_settings() { return settings_; }
73+
void set_core_settings(const CoreMemoryLruGcSettings& settings) {
74+
settings_ = settings;
75+
}
76+
77+
private:
78+
CoreMemoryLruGcSettings settings_;
79+
};
80+
4781
class MemoryCacheSettingsInternal final : public LocalCacheSettingsInternal {
4882
public:
4983
explicit MemoryCacheSettingsInternal(const CoreMemorySettings& core_settings)

0 commit comments

Comments
 (0)