这个==~
布尔运算符在下面的代码中做了什么?
springcacheCacheManager.cacheNames.each { name ->
if (cacheNamePatterns.any { name ==~ it }) {
flushNamedCache(name)
}
}
答案 0 :(得分:2)
match operator执行正则表达式匹配:
def regex = "[A-Z]{2,}"
assert "wot" !=~ regex
assert "A" !=~ regex
assert "ABC" ==~ regex
在您的代码中,如果cacheName
与任何cacheNamePatterns
匹配,则会刷新它:
def cacheNames = ['html', 'res/images', 'res/js']
def cacheNamePatterns = ['res/.*']
def flushedCaches = []
cacheNames.each { name ->
if (cacheNamePatterns.any { name ==~ it }) {
flushedCaches << name
}
}
assert flushedCaches == ['res/images', 'res/js']