1- using System ;
21using LaunchDarkly . Sdk . Internal . Concurrent ;
32using LaunchDarkly . Sdk . Server . Subsystems ;
43
@@ -26,15 +25,18 @@ internal class WriteThroughStore : IDataStore, ITransactionalDataStore
2625 /// </para>
2726 /// </summary>
2827 private readonly AtomicBoolean _hasReceivedAnInitializingPayload = new AtomicBoolean ( false ) ;
28+
29+ private readonly DataSystemConfiguration . DataStoreMode _persistenceMode ;
2930
30- public WriteThroughStore ( IDataStore memoryStore , IDataStore persistentStore )
31+ public WriteThroughStore ( IDataStore memoryStore , IDataStore persistentStore , DataSystemConfiguration . DataStoreMode persistenceMode )
3132 {
3233 _memoryStore = memoryStore ;
3334 _txMemoryStore = ( ITransactionalDataStore ) _memoryStore ;
3435 _persistentStore = persistentStore ;
3536 _hasPersistence = persistentStore != null ;
3637 // During initializations read will happen from the persistent store.
3738 _activeReadStore = _hasPersistence ? _persistentStore : _memoryStore ;
39+ _persistenceMode = persistenceMode ;
3840 }
3941
4042 public void Dispose ( )
@@ -56,7 +58,11 @@ private void Dispose(bool disposing)
5658 public void Init ( DataStoreTypes . FullDataSet < DataStoreTypes . ItemDescriptor > allData )
5759 {
5860 _memoryStore . Init ( allData ) ;
59- _persistentStore ? . Init ( allData ) ;
61+ if ( _persistenceMode == DataSystemConfiguration . DataStoreMode . ReadWrite )
62+ {
63+ _persistentStore ? . Init ( allData ) ;
64+ }
65+
6066 MaybeSwitchStore ( ) ;
6167 }
6268
@@ -73,7 +79,7 @@ public void Init(DataStoreTypes.FullDataSet<DataStoreTypes.ItemDescriptor> allDa
7379 public bool Upsert ( DataStoreTypes . DataKind kind , string key , DataStoreTypes . ItemDescriptor item )
7480 {
7581 var result = _memoryStore . Upsert ( kind , key , item ) ;
76- if ( _hasPersistence )
82+ if ( _hasPersistence && _persistenceMode == DataSystemConfiguration . DataStoreMode . ReadWrite )
7783 {
7884 result &= _persistentStore . Upsert ( kind , key , item ) ;
7985 }
@@ -93,7 +99,7 @@ public void Apply(DataStoreTypes.ChangeSet<DataStoreTypes.ItemDescriptor> change
9399 {
94100 _txMemoryStore . Apply ( changeSet ) ;
95101
96- if ( _hasPersistence )
102+ if ( _hasPersistence && _persistenceMode == DataSystemConfiguration . DataStoreMode . ReadWrite )
97103 {
98104 if ( _persistentStore is ITransactionalDataStore txPersistentStore )
99105 {
0 commit comments