3

Does craft()->cache-> have a way of returning all the cache records? I need to delete some caches, but only if the key begins with a certain prefix, “ranking__getAthletePoints_”. I won’t know the numbers following in the key names. If I could grab all of them, I assume I could check against the key names with something like startsWith() and delete the correct caches that way.

Very much out of my element with php & plugin development! Thanks for any help!

1

Not without some brute-force cracking.

The keys you pass into CFileCache's set and get methods are an md5 hash of your key prepended with your Craft installation's appId (which by default is a randomly generated string).

So with a key of testKey, that could end up as a value of 3f8b3c45a9c6f395d02b930f18910a92. For CFileCache, that value ends up being the file name of the cache file and gets put in craft/storage/runtime/cache/3f8b3c45a9c6f395d02b930f18910a92.bin.

Later, when you call get and pass in the key of testKey, it goes through the same process and checks to see if a file named 3f8b3c45a9c6f395d02b930f18910a92.bin exists. If it does, it knows there is a match.

As you can see, there's no way to find that match without knowing the key ahead of time (unless you brute-force cracked md5, which is doable, but probably not practical for your use-case).

1
  • Well yeah, "brute-force crack" is my middle name ;) ... Alright, thanks for the answer Brad. I'll have to rethink ways to go about my plugin. Dec 15 '15 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.