Skip to content

Commit dcdbab2

Browse files
committed
Initialize GetContentTypeDescriptors() cache on Load()
When `SqlTopicRepository.Load()` is called, attempt to update the `GetContentTypeDescriptors()` cache by calling the new `SetContentTypeDescriptors()` overload (78a9d3f). There are two main advantages to this. First, it helps prevent an unnecessary and redundant call to the database in order to initialize the `GetContentTypeDescriptors()` cache. Second, it helps further ensure that the object references used by that cache are the same ones used by any subsequent caching layer since, in practice, the first call to `Load()` will be to warm the site cache by pulling the entire topic graph. (Unfortunately, because `CachedTopicRepository` uses a decorator pattern, it can't otherwise share the cache very easily with the underlying `ITopicRepository` instance, since that instance isn't guaranteed to inherit from `TopicRepositoryBase`—and since it isn't using actual inheritance. The decorator pattern allows the `CachedTopicRepository` to be used with _any_ implementation, not just the e.g., `SqlTopicRepository`, so this makes sense. But given that, we need to get creative to avoid versioning conflicts between caches. In most cases, this update should mitigate that.)
1 parent c75bbe2 commit dcdbab2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ public override Topic Load(int topicId, bool isRecursive = true) {
173173
}
174174
}
175175

176+
/*------------------------------------------------------------------------------------------------------------------------
177+
| Establish content type cache
178+
>-------------------------------------------------------------------------------------------------------------------------
179+
| If this load represents the entire topic graph, then relay the content type configuration to the TopicRepositoryBase in
180+
| order to either update or establish the content type cache. Not only does this prevent the need for a separate redundant
181+
| call later but, even more importantly, it helps ensure the same object references are maintained so that any updates to
182+
| subsequently cached content types are available.
183+
\-----------------------------------------------------------------------------------------------------------------------*/
184+
base.SetContentTypeDescriptors(topic);
185+
176186
/*------------------------------------------------------------------------------------------------------------------------
177187
| Return objects
178188
\-----------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)