This I really like. but it seems it does not quite solve the problem (or could likely cause extra downloads)
This second version I don’t like as much. Not the code itself (looks good!) but the fact that it would likely be a very expensive bit of code to run for large projects.
All in all, I’m liking this less and less. For example, say you had this scenario:
Key “tank” → bundleA, bundleB
key “tree” → bundleC, bundleB
now, at some point, you say you want to ClearCache(“tank”). The cheap solution is obviously no good, because it’d delete bundleB. So that’s out. But what if we do the expensive solution. It’ll remove bundleA, but not bundleB because “tree” needs it.
Now some time later, you say ClearCache(“tree”). Ideally, this would clear C & B, because you already told us you don’t need tree anymore. But we won’t know that. So we’ll delete bundleC, but not bundleB.
And this is a very clean example. In reality, there will be so many cross dependencies that a ClearCache would rarely give you something you actually wanted or found beneficial.
I think the better answer is a feature we are working on for keys removed or changed in the catalog. This would, on catalog update, remove bundles no longer referenced. Say you had the above tree & tank example. Now you do a content update, and “tank” no longer exists. Our code would remove “bundleA”. Or maybe “tank” was updated, and pointed now to bundleA2 and bundleB2. That would remove “bundleA” in that scenario as well.
This feature isn’t done, but will likely be done far sooner than the ClearCache API.
At least that’s my current opinion based on my understanding of the feature, because…
a) you can write your own code to do it
b) it adds danger of introducing bugs and causing re-downloads of valid data
c) i don’t actually see it as being useful in many real world scenarios.
I could be wrong though. feel free to reply and convince me otherwise.