Skip to content

Commit adb929d

Browse files
Merge pull request #111 from TransactionProcessing/task/#110_configurablesscache
Make cache configurable
2 parents 011890d + 78cd511 commit adb929d

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

Shared.EventStore/SubscriptionWorker/SubscriptionRepository.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public class SubscriptionRepository : ISubscriptionRepository
2828

2929
#region Constructors
3030

31-
private SubscriptionRepository()
31+
private SubscriptionRepository(Int32 cacheDuration = 120)
3232
{
3333
this.Subscriptions = new PersistentSubscriptions();
3434

35-
this.RefreshRequired = (force, s) => force || s.InitialState || SubscriptionRepository.RefreshNeeded(s.LastTimeRefreshed);
35+
this.RefreshRequired = (force, s) => force || s.InitialState || SubscriptionRepository.RefreshNeeded(s.LastTimeRefreshed, cacheDuration);
3636
}
3737

3838
#endregion
@@ -45,28 +45,28 @@ private SubscriptionRepository()
4545

4646
#region Methods
4747

48-
public static SubscriptionRepository Create(String eventStoreConnectionString)
48+
public static SubscriptionRepository Create(String eventStoreConnectionString,Int32 cacheDuration = 120)
4949
{
5050
EventStoreClientSettings settings = EventStoreClientSettings.Create(eventStoreConnectionString);
5151
HttpClient httpClient = SubscriptionWorkerHelper.CreateHttpClient(settings);
5252

53-
return new SubscriptionRepository
53+
return new SubscriptionRepository(cacheDuration)
5454
{
5555
GetAllSubscriptions = cancellationToken => SubscriptionRepository.GetSubscriptions(httpClient, cancellationToken)
5656
};
5757
}
5858

59-
public static SubscriptionRepository Create(Task<List<PersistentSubscriptionInfo>> func)
59+
public static SubscriptionRepository Create(Task<List<PersistentSubscriptionInfo>> func,Int32 cacheDuration = 120)
6060
{
61-
return new()
61+
return new(cacheDuration)
6262
{
6363
GetAllSubscriptions = _ => func
6464
};
6565
}
6666

67-
public static SubscriptionRepository Create(Func<CancellationToken, Task<List<PersistentSubscriptionInfo>>> func)
67+
public static SubscriptionRepository Create(Func<CancellationToken, Task<List<PersistentSubscriptionInfo>>> func,Int32 cacheDuration = 120)
6868
{
69-
return new()
69+
return new(cacheDuration)
7070
{
7171
GetAllSubscriptions = func
7272
};
@@ -147,16 +147,11 @@ private PersistentSubscriptions GetSubscriptionsFromCache(String reason)
147147
return this.Subscriptions;
148148
}
149149

150-
private static Boolean RefreshNeeded(DateTime lastRefreshed)
150+
private static Boolean RefreshNeeded(DateTime lastRefreshed, Int32 cacheDuration)
151151
{
152152
TimeSpan elapsed = DateTime.Now - lastRefreshed;
153153

154-
//TODO: Add to configuration
155-
//OR this.PersistentSubscriptionPollingInSeconds x 2 ?
156-
//60 seconds is how often we are willing to refresh our cache.
157-
//I suspect this could be much higher (trade of with update the UI and wanting response, versus how often we hot the hit ES essentially getting
158-
//the same information each time.
159-
if (elapsed.TotalSeconds < 120)
154+
if (elapsed.TotalSeconds < cacheDuration)
160155
{
161156
return false;
162157
}

0 commit comments

Comments
 (0)