-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimised the XPath Handlebars helper's performance by caching parsed…
… XML documents and evaluated XPath expressions
- Loading branch information
1 parent
fb15c65
commit 92e2e10
Showing
5 changed files
with
167 additions
and
14 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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/RenderCache.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,59 @@ | ||
package com.github.tomakehurst.wiremock.extension.responsetemplating; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
public class RenderCache { | ||
|
||
private final Map<Key, Object> cache = new HashMap<>(); | ||
|
||
public void put(Key key, Object value) { | ||
cache.put(key, value); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T get(Key key) { | ||
return (T) cache.get(key); | ||
} | ||
|
||
public static class Key { | ||
private final Class<?> forClass; | ||
private final List<?> elements; | ||
|
||
public static Key keyFor(Class<?> forClass, Object... elements) { | ||
return new Key(forClass, asList(elements)); | ||
} | ||
|
||
private Key(Class<?> forClass, List<?> elements) { | ||
this.forClass = forClass; | ||
this.elements = elements; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("Key{"); | ||
sb.append("forClass=").append(forClass); | ||
sb.append(", elements=").append(elements); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Key key = (Key) o; | ||
return forClass.equals(key.forClass) && | ||
elements.equals(key.elements); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(forClass, elements); | ||
} | ||
} | ||
} |
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