In brief i'm w开发者_如何学编程riting a plugin for a Rails app and I want to cache the data the plugin generates, however I want the ability to delete the cached items should I need to do so.
e.g.
Rails.cache.write("data_1", "the data")
Rails.cache.write("data_2", "the data")
Rails.cache.write("data_3", "the data")
What should I be calling to fetch all keys that match the regex /^data_/ so I can delete them?
I tried:
Rails.cache.fetch(/^data_/)
Rails.cache.read(/^data_/)
Any help/pointers would be greatly appreciated.
You can use .match
. So something like this should work:
if Rails.cache.fetch(..).match(/^data_/)
do something
精彩评论