{"action":"created","issue":{"url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput/issues/182","repository_url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput","labels_url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput/issues/182/labels{/name}","comments_url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput/issues/182/comments","events_url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput/issues/182/events","html_url":"https://github.com/filipw/Strathweb.CacheOutput/issues/182","id":175853719,"number":182,"title":"RemoveStartsWith not working","user":{"login":"im1dermike","id":994232,"avatar_url":"https://avatars0.githubusercontent.com/u/994232?v=3","gravatar_id":"","url":"https://api.github.com/users/im1dermike","html_url":"https://github.com/im1dermike","followers_url":"https://api.github.com/users/im1dermike/followers","following_url":"https://api.github.com/users/im1dermike/following{/other_user}","gists_url":"https://api.github.com/users/im1dermike/gists{/gist_id}","starred_url":"https://api.github.com/users/im1dermike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/im1dermike/subscriptions","organizations_url":"https://api.github.com/users/im1dermike/orgs","repos_url":"https://api.github.com/users/im1dermike/repos","events_url":"https://api.github.com/users/im1dermike/events{/privacy}","received_events_url":"https://api.github.com/users/im1dermike/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-08T20:19:07Z","updated_at":"2017-04-06T09:33:12Z","closed_at":null,"body":"I have the following `GetLogo()` method on my controller:\n\n```\n[CacheOutput(ClientTimeSpan = 86400, ServerTimeSpan = 86400)]\n[Route(\"{id:int}/logo\")]\npublic HttpResponseMessage GetLogo(int id)\n{\n}\n```\n\nWhen a cache entry is created for this controller, the keys look like this:\n\n```\nwebnamespace.apicontrollers.plancontroller-getlogo-id=3:application/json; charset=utf-8:response-ct\n```\n\nI saw another issue which I believe referenced keys not being what one would expect when route attributes are used.  Given that, I'm trying to invalidate cache for `GetLogo()` for individual `id` values like this:\n\n```\nvar cache = Configuration.CacheOutputConfiguration().GetCacheOutputProvider(Request);\nvar keyPrefix = String.Format(\"{0}-id={1}\", \n    Configuration.CacheOutputConfiguration().MakeBaseCachekey(\n        (PlanController t) => t.GetLogo(planId)), planId);\ncache.RemoveStartsWith(keyPrefix);\n```\n\nIn this case, `keyPrefix` is `webnamespace.apicontrollers.plancontroller-getlogo-id=3` which is how multiple keys start, but none end up being removed.  \n\nLastly, when I check `cache.AllKeys.ToList().Where(x => x.StartsWith(keyPrefix))`, after the line instantiating `keyPrefix`, it returns multiple items.  The only way I can invalidate the cache is by doing this:\n\n```\nvar keys = cache.AllKeys.ToList().Where(x => x.StartsWith(keyPrefix));\nforeach (var key in keys)\n{\n    cache.Remove(key);\n}\n```\n\nWhy is this not working?\n"},"comment":{"url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput/issues/comments/292120323","html_url":"https://github.com/filipw/Strathweb.CacheOutput/issues/182#issuecomment-292120323","issue_url":"https://api.github.com/repos/filipw/Strathweb.CacheOutput/issues/182","id":292120323,"user":{"login":"dmalanij","id":13454997,"avatar_url":"https://avatars1.githubusercontent.com/u/13454997?v=3","gravatar_id":"","url":"https://api.github.com/users/dmalanij","html_url":"https://github.com/dmalanij","followers_url":"https://api.github.com/users/dmalanij/followers","following_url":"https://api.github.com/users/dmalanij/following{/other_user}","gists_url":"https://api.github.com/users/dmalanij/gists{/gist_id}","starred_url":"https://api.github.com/users/dmalanij/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmalanij/subscriptions","organizations_url":"https://api.github.com/users/dmalanij/orgs","repos_url":"https://api.github.com/users/dmalanij/repos","events_url":"https://api.github.com/users/dmalanij/events{/privacy}","received_events_url":"https://api.github.com/users/dmalanij/received_events","type":"User","site_admin":false},"created_at":"2017-04-06T09:33:12Z","updated_at":"2017-04-06T09:33:12Z","body":"@im1dermike, if you take a look at how the `MemoryCacheDefault` is implemented you'll realize that what you're experience is due to the design of it. Probably the naming of methods is not the best (I'm planning to write a few things for this project, will take notes on this), `RemoveStartsWith` should be better called `RemoveKeyAndDependants` as it's meant to be working with the dependency mechanisms that the `MemoryCache` provides.\r\n\r\nYou might want to take a look at #146 that seems to be suitable for your scenario. Otherwise, you might need to extend the `IApiOutputCache` with new method that then you implment based on the workaround you mentioned. Yes, you can try doing same thing by overriding completely the `MemoryCacheDefault` with your approach, but that will have performance issues when getting large amount of items in the cache, that's why I suggest using a separate method for this particular scenario not messing with the rest of the infrastructure.\r\n\r\nHope this helps, cheers!"}}
{"actor":{"display_login":"dmalanij"}}