-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c730b94
commit 92d8a20
Showing
17 changed files
with
305 additions
and
111 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
59 changes: 59 additions & 0 deletions
59
orcid-web/src/main/java/org/orcid/frontend/util/AuthorizationRequestLocalCache.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 org.orcid.frontend.util; | ||
import org.ehcache.Cache; | ||
import org.ehcache.CacheManager; | ||
import org.ehcache.config.builders.CacheConfigurationBuilder; | ||
import org.ehcache.config.builders.CacheManagerBuilder; | ||
import org.ehcache.config.builders.ResourcePoolsBuilder; | ||
import org.ehcache.expiry.Duration; | ||
import org.ehcache.expiry.Expirations; | ||
import org.orcid.pojo.ajaxForm.RequestInfoForm; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.oauth2.provider.AuthorizationRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Component | ||
public class AuthorizationRequestLocalCache { | ||
|
||
@Value("${org.orcid.core.session.localCache.ttl:900}") | ||
private int cacheTTLInSeconds; | ||
|
||
@Value("${org.orcid.core.session.localCache.heap:10000}") | ||
private int heapSize; | ||
|
||
private CacheManager cacheManager; | ||
private Cache<String, AuthorizationRequest> cache; | ||
|
||
public AuthorizationRequestLocalCache() { | ||
cacheManager = CacheManagerBuilder | ||
.newCacheManagerBuilder().build(); | ||
cacheManager.init(); | ||
} | ||
|
||
@PostConstruct | ||
public void initCache() { | ||
cache = cacheManager | ||
.createCache("squaredNumber", CacheConfigurationBuilder | ||
.newCacheConfigurationBuilder( | ||
String.class, AuthorizationRequest.class, | ||
ResourcePoolsBuilder.heap(heapSize)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(cacheTTLInSeconds, TimeUnit.SECONDS)))); | ||
} | ||
|
||
public AuthorizationRequest get(String key) { | ||
return cache.get(key); | ||
} | ||
|
||
public void put(String key, AuthorizationRequest value) { | ||
cache.put(key, value); | ||
} | ||
|
||
public void remove(String key) { | ||
cache.remove(key); | ||
} | ||
|
||
public boolean containsKey(String key) { | ||
return cache.containsKey(key); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
orcid-web/src/main/java/org/orcid/frontend/util/OriginalAuthorizationRequestLocalCache.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 org.orcid.frontend.util; | ||
import org.ehcache.Cache; | ||
import org.ehcache.CacheManager; | ||
import org.ehcache.config.builders.CacheConfigurationBuilder; | ||
import org.ehcache.config.builders.CacheManagerBuilder; | ||
import org.ehcache.config.builders.ResourcePoolsBuilder; | ||
import org.ehcache.expiry.Duration; | ||
import org.ehcache.expiry.Expirations; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.oauth2.provider.AuthorizationRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Component | ||
public class OriginalAuthorizationRequestLocalCache { | ||
|
||
@Value("${org.orcid.core.session.localCache.ttl:900}") | ||
private int cacheTTLInSeconds; | ||
|
||
@Value("${org.orcid.core.session.localCache.heap:10000}") | ||
private int heapSize; | ||
|
||
private CacheManager cacheManager; | ||
private Cache<String, Map> cache; | ||
|
||
public OriginalAuthorizationRequestLocalCache() { | ||
cacheManager = CacheManagerBuilder | ||
.newCacheManagerBuilder().build(); | ||
cacheManager.init(); | ||
} | ||
|
||
@PostConstruct | ||
public void initCache() { | ||
cache = cacheManager | ||
.createCache("squaredNumber", CacheConfigurationBuilder | ||
.newCacheConfigurationBuilder( | ||
String.class, Map.class, | ||
ResourcePoolsBuilder.heap(heapSize)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(cacheTTLInSeconds, TimeUnit.SECONDS)))); | ||
} | ||
|
||
public Map get(String key) { | ||
return cache.get(key); | ||
} | ||
|
||
public void put(String key, Map value) { | ||
cache.put(key, value); | ||
} | ||
|
||
public void remove(String key) { | ||
cache.remove(key); | ||
} | ||
|
||
public boolean containsKey(String key) { | ||
return cache.containsKey(key); | ||
} | ||
} |
Oops, something went wrong.