congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
SoftExpiringCache.getElement
Code IndexAdd Tabnine to your IDE (free)

How to use
getElement
method
in
org.apache.shindig.common.cache.SoftExpiringCache

Best Java code snippets using org.apache.shindig.common.cache.SoftExpiringCache.getElement (Showing top 20 results out of 315)

origin: org.apache.shindig/shindig-common

@Test
public void testGeneralCacheExpiration() {
 SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
 String key = "key1", val = "val1";
 expiringCache.addElement(key, val, 240 * 1000);
 // Time is still 0: should be in the cache.
 assertEquals(val, expiringCache.getElement(key).obj);
 assertFalse(expiringCache.getElement(key).isExpired);
 // Time = 300 seconds: out of cache.
 timeSource.setCurrentTimeMillis(300 * 1000);
 assertEquals(val, expiringCache.getElement(key).obj);
 assertTrue(expiringCache.getElement(key).isExpired);
}
origin: org.gatein.shindig/shindig-common

@Test
public void testGeneralCacheExpiration() {
 SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
 String key = "key1", val = "val1";
 expiringCache.addElement(key, val, 240 * 1000);
 // Time is still 0: should be in the cache.
 assertEquals(val, expiringCache.getElement(key).obj);
 assertFalse(expiringCache.getElement(key).isExpired);
 // Time = 300 seconds: out of cache.
 timeSource.setCurrentTimeMillis(300 * 1000);
 assertEquals(val, expiringCache.getElement(key).obj);
 assertTrue(expiringCache.getElement(key).isExpired);
}
origin: org.wso2.org.apache.shindig/shindig-common

@Test
public void testGeneralCacheExpiration() {
 SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
 String key = "key1", val = "val1";
 expiringCache.addElement(key, val, 240 * 1000);
 // Time is still 0: should be in the cache.
 assertEquals(val, expiringCache.getElement(key).obj);
 assertFalse(expiringCache.getElement(key).isExpired);
 // Time = 300 seconds: out of cache.
 timeSource.setCurrentTimeMillis(300 * 1000);
 assertEquals(val, expiringCache.getElement(key).obj);
 assertTrue(expiringCache.getElement(key).isExpired);
}
origin: com.lmco.shindig/shindig-common

@Test
public void testGeneralCacheExpiration() {
 SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
 String key = "key1", val = "val1";
 expiringCache.addElement(key, val, 240 * 1000);
 // Time is still 0: should be in the cache.
 assertEquals(val, expiringCache.getElement(key).obj);
 assertFalse(expiringCache.getElement(key).isExpired);
 // Time = 300 seconds: out of cache.
 timeSource.setCurrentTimeMillis(300 * 1000);
 assertEquals(val, expiringCache.getElement(key).obj);
 assertTrue(expiringCache.getElement(key).isExpired);
}
origin: apache/shindig

@Test
public void testGeneralCacheExpiration() {
 SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
 String key = "key1", val = "val1";
 expiringCache.addElement(key, val, 240 * 1000);
 // Time is still 0: should be in the cache.
 assertEquals(val, expiringCache.getElement(key).obj);
 assertFalse(expiringCache.getElement(key).isExpired);
 // Time = 300 seconds: out of cache.
 timeSource.setCurrentTimeMillis(300 * 1000);
 assertEquals(val, expiringCache.getElement(key).obj);
 assertTrue(expiringCache.getElement(key).isExpired);
}
origin: com.lmco.shindig/shindig-common

 @Test
 public void testMissingValue() {
  SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
  assertNull(expiringCache.getElement("not set"));
 }
}
origin: org.apache.shindig/shindig-common

 @Test
 public void testMissingValue() {
  SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
  assertNull(expiringCache.getElement("not set"));
 }
}
origin: org.wso2.org.apache.shindig/shindig-common

 @Test
 public void testMissingValue() {
  SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
  assertNull(expiringCache.getElement("not set"));
 }
}
origin: org.gatein.shindig/shindig-common

 @Test
 public void testMissingValue() {
  SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
  assertNull(expiringCache.getElement("not set"));
 }
}
origin: org.apache.shindig/shindig-gadgets

Object obj = null;
if (!query.ignoreCache) {
 SoftExpiringCache.CachedObject<Object> cached = cache.getElement(query.specUri.toString());
 if (cached != null) {
  obj = cached.obj;
origin: apache/shindig

 @Test
 public void testMissingValue() {
  SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
  assertNull(expiringCache.getElement("not set"));
 }
}
origin: com.lmco.shindig/shindig-gadgets

  + info.message.getParameter("oauth_nonce");
CachedObject<OAuthMessage> previousMessage = nonceCache.getElement(nonceKey);
if (previousMessage != null) {
 throw new RuntimeException("Reused nonce, old message = " + previousMessage.obj
origin: org.apache.shindig/shindig-gadgets

  + info.message.getParameter("oauth_nonce");
CachedObject<OAuthMessage> previousMessage = nonceCache.getElement(nonceKey);
if (previousMessage != null) {
 throw new RuntimeException("Reused nonce, old message = " + previousMessage.obj
origin: org.wso2.org.apache.shindig/shindig-gadgets

  + info.message.getParameter("oauth_nonce");
CachedObject<OAuthMessage> previousMessage = nonceCache.getElement(nonceKey);
if (previousMessage != null) {
 throw new RuntimeException("Reused nonce, old message = " + previousMessage.obj
origin: com.lmco.shindig/shindig-gadgets

@Test
public void staleSpecReturnedFromCacheOnError() throws Exception {
 HttpRequest request = createIgnoreCacheRequest();
 HttpRequest retriedRequest = createCacheableRequest();
 HttpResponse expiredResponse = new HttpResponseBuilder()
   .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
   .addHeader("Pragma", "no-cache")
   .create();
 expect(pipeline.execute(request)).andReturn(expiredResponse);
 expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once();
 replay(pipeline);
 specFactory.getGadgetSpec(createContext(SPEC_URL, true));
 SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL);
 specFactory.cache.addElement(SPEC_URL, inCache.obj, -1);
 GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false));
 assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
}
origin: com.lmco.shindig/shindig-gadgets

@Test
public void staleSpecIsRefetched() throws Exception {
 HttpRequest request = createIgnoreCacheRequest();
 HttpRequest retriedRequest = createCacheableRequest();
 HttpResponse expiredResponse = new HttpResponseBuilder()
   .addHeader("Pragma", "no-cache")
   .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
   .create();
 HttpResponse updatedResponse = new HttpResponse(ALT_LOCAL_SPEC_XML);
 expect(pipeline.execute(request)).andReturn(expiredResponse).once();
 expect(pipeline.execute(retriedRequest)).andReturn(updatedResponse).once();
 replay(pipeline);
 specFactory.getGadgetSpec(createContext(SPEC_URL, true));
 SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL);
 specFactory.cache.addElement(SPEC_URL, inCache.obj, -1);
 GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false));
 assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
}
origin: org.wso2.org.apache.shindig/shindig-gadgets

@Test
public void staleSpecReturnedFromCacheOnError() throws Exception {
 HttpRequest request = createIgnoreCacheRequest();
 HttpRequest retriedRequest = createCacheableRequest();
 HttpResponse expiredResponse = new HttpResponseBuilder()
   .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
   .addHeader("Pragma", "no-cache")
   .create();
 expect(pipeline.execute(request)).andReturn(expiredResponse);
 expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once();
 replay(pipeline);
 specFactory.getGadgetSpec(createContext(SPEC_URL, true));
 SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString());
 specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1);
 GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false));
 assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
}
origin: org.wso2.org.apache.shindig/shindig-gadgets

@Test
public void staleSpecIsRefetched() throws Exception {
 HttpRequest request = createIgnoreCacheRequest();
 HttpRequest retriedRequest = createCacheableRequest();
 HttpResponse expiredResponse = new HttpResponseBuilder()
   .addHeader("Pragma", "no-cache")
   .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
   .create();
 HttpResponse updatedResponse = new HttpResponse(ALT_LOCAL_SPEC_XML);
 expect(pipeline.execute(request)).andReturn(expiredResponse).once();
 expect(pipeline.execute(retriedRequest)).andReturn(updatedResponse).once();
 replay(pipeline);
 specFactory.getGadgetSpec(createContext(SPEC_URL, true));
 SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString());
 specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1);
 GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false));
 assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
}
origin: org.apache.shindig/shindig-gadgets

@Test
public void staleSpecReturnedFromCacheOnError() throws Exception {
 HttpRequest request = createIgnoreCacheRequest();
 HttpRequest retriedRequest = createCacheableRequest();
 HttpResponse expiredResponse = new HttpResponseBuilder()
   .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
   .addHeader("Pragma", "no-cache")
   .create();
 expect(pipeline.execute(request)).andReturn(expiredResponse);
 expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once();
 replay(pipeline);
 specFactory.getGadgetSpec(createContext(SPEC_URL, true));
 SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString());
 specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1);
 GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false));
 assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
}
origin: org.apache.shindig/shindig-gadgets

@Test
public void staleSpecIsRefetched() throws Exception {
 HttpRequest request = createIgnoreCacheRequest();
 HttpRequest retriedRequest = createCacheableRequest();
 HttpResponse expiredResponse = new HttpResponseBuilder()
   .addHeader("Pragma", "no-cache")
   .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
   .create();
 HttpResponse updatedResponse = new HttpResponse(ALT_LOCAL_SPEC_XML);
 expect(pipeline.execute(request)).andReturn(expiredResponse).once();
 expect(pipeline.execute(retriedRequest)).andReturn(updatedResponse).once();
 replay(pipeline);
 specFactory.getGadgetSpec(createContext(SPEC_URL, true));
 SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString());
 specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1);
 GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false));
 assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent());
}
org.apache.shindig.common.cacheSoftExpiringCachegetElement

Javadoc

Retrieve an element from the cache by key. If there is no such element for that key in the cache, or if the element has timed out, null is returned.

Popular methods of SoftExpiringCache

  • <init>
    Create a new TtlCache with the given capacity and TTL values. The cache provider provides an impleme
  • addElement
    Add an element to the cache, with the intended max age for its cache entry provided in milliseconds.
  • setTimeSource
    Set a new time source. For use in testing.

Popular in Java

  • Start an intent from android
  • getExternalFilesDir (Context)
  • onRequestPermissionsResult (Fragment)
  • onCreateOptionsMenu (Activity)
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • JComboBox (javax.swing)
  • JOptionPane (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Table (org.hibernate.mapping)
    A relational table
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now