Package play.cache

Examples of play.cache.CacheApi


        return new News();
    }

    @Test
    public void getOrElse() {
        CacheApi cache = app.getWrappedApplication().injector().instanceOf(CacheApi.class);

        //#get-or-else
        News maybeCached = cache.getOrElse("item.key", () -> lookUpFrontPageNews());
        //#get-or-else

        assertNotNull(maybeCached);
    }
View Full Code Here


        app.getWrappedApplication().injector().instanceOf(javaguide.cache.qualified.Application.class);
    }

    @Test
    public void simple() {
        CacheApi cache = app.getWrappedApplication().injector().instanceOf(CacheApi.class);

        News frontPageNews = new News();
        //#simple-set
        cache.set("item.key", frontPageNews);
        //#simple-set
        //#time-set
        // Cache for 15 minutes
        cache.set("item.key", frontPageNews, 60 * 15);
        //#time-set
        //#get
        News news = cache.get("item.key");
        //#get
        assertThat(news, equalTo(frontPageNews));
        //#get-or-else
        News maybeCached = cache.getOrElse("item.key", new Callable<News>() {
            public News call() {
                return lookUpFrontPageNews();
            }
        });
        //#get-or-else
        //#remove
        cache.remove("item.key");
        //#remove
        assertThat(cache.get("item.key"), nullValue());
    }
View Full Code Here

        //#http
    }

    @Test
    public void http() {
        CacheApi cache = app.getWrappedApplication().injector().instanceOf(CacheApi.class);

        assertThat(contentAsString(MockJavaActionHelper.call(new Controller1(), fakeRequest())), equalTo("Hello world"));
        assertThat(cache.get("homePage"), notNullValue());
        cache.set("homePage", Results.ok("something else"));
        assertThat(contentAsString(MockJavaActionHelper.call(new Controller1(), fakeRequest())), equalTo("something else"));
    }
View Full Code Here

TOP

Related Classes of play.cache.CacheApi

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.