Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Last active December 15, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyond-code-github/5244422 to your computer and use it in GitHub Desktop.
Save beyond-code-github/5244422 to your computer and use it in GitHub Desktop.
Cache invalidation use-case #1
I have a URI used to manipulate data records:
http://api/{AppId}/AppData/
There is also the ability to retrieve several report dataviews based on the records.
http://api/{AppId}/ChartData/{chartId}
I need a mechanism so that when I POST to http://api/{AppId}/AppData/, or DELETE\PATCH to http://api/{AppId}/AppData/{id} then any cached route starting with http://api/{AppId}/ChartData/ gets invalidated.
* Can't use LinkedRouteProvider without hitting the db to discover all reports, which will hurt performance.
* Could potentially cache available report ids somewhere but this seems hacky
* Reports store a different view of the data so cannot share cache keys
* Data is projected using legacy code in C# which cannot easily move client side
Have investigated the possibility of invalidating routes using regex, but concerned about performance of this. Also it would not work for all EntityTagStores (for example Regex is not supported by SQL without a CLR SP)
Am now toying with the idea of creating a 'HierarchicalEntityTagStore' which splits URIs and stores them in a tree structure according to their route segments which would mean we can traverse it and invalidate related caches in a highly performant manner, eg:
[
{
segment: "1", // AppId
children: [
{
segment: "AppData",
children: [
{
segment: "ABCDEF", // Id
entitytags: [ ... ]
},
{
segment: "ZXYWV", // Id
entitytags: [ ... ]
}
]
},
{
segment: "ChartData",
children: [
{
segment: "3", // ChartId
entitytags: [ ... ]
},
{
segment: "4", // ChartId
entitytags: [ ... ]
}
]
}
]
},
...
...
...
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment