Skip to content

Commit ea40bbb

Browse files
committed
Established new Counter view for the Page content type
This view establishes a basic counter that increments on a per-path basis. This will simplify output caching for the new `[TopicResponseCache]` attribute (9bc5797). As part of this, updated the new `/Web/CachedPage` stub data (8cbf7da) to use this view.
1 parent 8cbf7da commit ea40bbb

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

OnTopic.AspNetCore.Mvc.IntegrationTests.Host/Repositories/StubTopicRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ private static Topic CreateFakeData() {
181181
cacheProfile.Attributes.SetValue("Location", "Any");
182182

183183
cachedPage.References.SetValue("CacheProfile", cacheProfile);
184+
cachedPage.Attributes.SetValue("View", "Counter");
185+
186+
uncachedPage.Attributes.SetValue("View", "Counter");
184187

185188
/*------------------------------------------------------------------------------------------------------------------------
186189
| Set to cache
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@getCounter()
2+
3+
@functions {
4+
5+
//Establish a counter for each page path
6+
public static Dictionary<string, int> pageCounter = new();
7+
8+
//Increment the counter for each call to a given page path
9+
public int getCounter() {
10+
var path = Context.Request.Path;
11+
if (!pageCounter.ContainsKey(path)) {
12+
pageCounter.Add(path, 0);
13+
}
14+
pageCounter[path] = pageCounter[path]+1;
15+
return pageCounter[path];
16+
}
17+
18+
}

0 commit comments

Comments
 (0)