Commit 0e5dec35 authored by Vladyslav Beznisko's avatar Vladyslav Beznisko
Browse files

Merge branch 'feature/PLAY-225' into '2.5.x'

Resolve PLAY-225 "Feature/"

See merge request !407
parents bc2dc381 1b6875fe
Pipeline #25672 passed with stages
in 19 minutes and 23 seconds
......@@ -53,11 +53,12 @@ import static ch.insign.playauth.inject.CacheProviderModule.PLAY_AUTH_CACHE;
*/
public class BlockCache {
private final static Logger logger = LoggerFactory.getLogger(BlockCache.class);
private final static Logger logger = LoggerFactory.getLogger(BlockCache.class);
private static final String PREFIX = "block-";
public static final String KEY_DELIMETER = "-";
@Inject
@Inject
private static @Named(PLAY_AUTH_CACHE) Cache authCache;
@Inject
private static @Named(BLOCK_CACHE) Cache blockCache;
......@@ -73,6 +74,7 @@ public class BlockCache {
private boolean ignoreUser = Configuration.getOrElse("cms.blockcache.ignoreUser", false);
private boolean ignoreGroups = Configuration.getOrElse("cms.blockcache.ignoreGroups", false);
private boolean ignoreLanguage = Configuration.getOrElse("cms.blockcache.ignoreLanguage", false);
private boolean ignoreUrl = Configuration.getOrElse("cms.blockcache.ignoreUrl", false);
private List<String> ignoreModifiedUrls = Configuration.getOrElse("cms.blockcache.ignoreModifiedUrls");
private List<String> ignoreGETParams = Configuration.getOrElse("cms.blockcache.ignoreGETParams");
......@@ -236,14 +238,19 @@ public class BlockCache {
StringBuilder sb = getFixedKeyPart();
if (!ignoreUrl){
sb.append(KEY_DELIMETER)
.append(Controller.request().path());
}
if (!ignoreLanguage) {
sb.append(Language.getCurrentLanguage());
sb.append(KEY_DELIMETER)
.append(Language.getCurrentLanguage());
}
if (!(ignoreUser && ignoreGroups)) {
Object currentUser = Optional.<Object>ofNullable(PlayAuth.getCurrentParty()).orElse(SecurityIdentity.ALL);
sb
.append("-")
sb.append(KEY_DELIMETER)
.append(PlayAuth.getAuthorizationHash(currentUser));
}
......@@ -259,7 +266,8 @@ public class BlockCache {
* @param sb string builder to add params into
*/
private void keyAddGETParams(StringBuilder sb) {
sb.append("-GET[");
sb.append(KEY_DELIMETER)
.append("GET[");
getParamsGET()
.forEach((s, strings) -> sb
.append(s)
......@@ -276,8 +284,7 @@ public class BlockCache {
private StringBuilder getFixedKeyPart() {
return new StringBuilder()
.append(PREFIX)
.append(block.getId())
.append("-");
.append(block.getId());
}
/**
......
......@@ -78,6 +78,8 @@ cms.blockcache.handlePOST = false
cms.blockcache.ignoreUser = false
cms.blockcache.ignoreGroups = false
cms.blockcache.ignoreLanguage = false
# By default, caching is done on per-url basis. Enable this option to prevent it.
cms.blockcache.ignoreUrl = false
# List of urls, which should be excluded from automatic block cache invalidation
# leave [] for disabled, use ["*"] for all urls
cms.blockcache.ignoreModifiedUrls = []
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment