Skip to content

Commit 7b2e7ad

Browse files
committed
Initialized `_cache_ as part of constructor
Whenever a `CachedTopicRepository` is called, it checked to see if the `_cache` was initialized. This should not be necessary. If a `CachedTopicRepository` is required, then it should immediately load its cache so it's ready for the first request. In most scenarios, this won't change the load time (as the `Load()` method will be called shortly after establishing the cache), but it does simplify the internal logic.
1 parent 5490fdb commit 7b2e7ad

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

Ignia.Topics.Data.Caching/CachedTopicRepository.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public CachedTopicRepository(ITopicRepository dataProvider) : base() {
5151
\-----------------------------------------------------------------------------------------------------------------------*/
5252
_dataProvider = dataProvider;
5353

54+
/*------------------------------------------------------------------------------------------------------------------------
55+
| Ensure topics are loaded
56+
\-----------------------------------------------------------------------------------------------------------------------*/
57+
_cache = _dataProvider.Load();
58+
5459
}
5560

5661
/*==========================================================================================================================
@@ -72,13 +77,6 @@ public CachedTopicRepository(ITopicRepository dataProvider) : base() {
7277
/// <returns>A topic object.</returns>
7378
public override Topic Load(int topicId, bool isRecursive = true) {
7479

75-
/*------------------------------------------------------------------------------------------------------------------------
76-
| Ensure topics are loaded
77-
\-----------------------------------------------------------------------------------------------------------------------*/
78-
if (_cache == null) {
79-
_cache = _dataProvider.Load();
80-
}
81-
8280
/*------------------------------------------------------------------------------------------------------------------------
8381
| Handle request for entire tree
8482
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -101,13 +99,6 @@ public override Topic Load(int topicId, bool isRecursive = true) {
10199
/// <returns>A topic object.</returns>
102100
public override Topic Load(string topicKey = null, bool isRecursive = true) {
103101

104-
/*------------------------------------------------------------------------------------------------------------------------
105-
| Ensure topics are loaded
106-
\-----------------------------------------------------------------------------------------------------------------------*/
107-
if (_cache == null) {
108-
_cache = _dataProvider.Load();
109-
}
110-
111102
/*------------------------------------------------------------------------------------------------------------------------
112103
| Lookup by TopicKey
113104
\-----------------------------------------------------------------------------------------------------------------------*/
@@ -218,8 +209,8 @@ private Topic GetTopic(Topic sourceTopic, string uniqueKey) {
218209
/// <param name="isDraft">Boolean indicator as to the topic's publishing status.</param>
219210
/// <returns>The integer return value from the execution of the <c>topics_UpdateTopic</c> stored procedure.</returns>
220211
/// <exception cref="Exception">
221-
/// The Content Type <c>topic.Attributes.GetValue(ContentType, Page)</c> referenced by <c>topic.Key</c> could not be found under
222-
/// Configuration:ContentTypes. There are <c>TopicRepository.ContentTypes.Count</c> ContentTypes in the Repository.
212+
/// The Content Type <c>topic.Attributes.GetValue(ContentType, Page)</c> referenced by <c>topic.Key</c> could not be found
213+
/// under Configuration:ContentTypes. There are <c>TopicRepository.ContentTypes.Count</c> ContentTypes in the Repository.
223214
/// </exception>
224215
/// <exception cref="Exception">
225216
/// Failed to save Topic <c>topic.Key</c> (<c>topic.Id</c>) via

0 commit comments

Comments
 (0)