-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly evict latest release stuff, store for longer, make it m…
…atch ignoring case
- Loading branch information
1 parent
2ffbab9
commit 7b9f4e5
Showing
5 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/io/papermc/hangar/util/IgnoringCaseCacheKeyGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.papermc.hangar.util; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.cache.interceptor.KeyGenerator; | ||
import org.springframework.cache.interceptor.SimpleKey; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class IgnoringCaseCacheKeyGenerator implements KeyGenerator { | ||
|
||
@Override | ||
public @NotNull Object generate(final @NotNull Object target, final @NotNull Method method, final Object... params) { | ||
if (params.length == 0) { | ||
return SimpleKey.EMPTY; | ||
} | ||
if (params.length == 1) { | ||
Object param = params[0]; | ||
if (param instanceof String s) { | ||
return s.toLowerCase(); | ||
} else if (param != null && !param.getClass().isArray()) { | ||
return param; | ||
} | ||
} | ||
|
||
Object[] elements = Arrays.copyOf(params, params.length); | ||
for (int i = 0; i < elements.length; i++) { | ||
if (elements[i] instanceof String s) { | ||
elements[i] = s.toLowerCase(); | ||
} | ||
} | ||
return new SimpleKey(elements); | ||
} | ||
} |