开发者

Using a regex to query the Rails cache to allow partial matches and return multiple items

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜