11/*
2+ * Copyright 2021 webtau maintainers
23 * Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
34 *
45 * Licensed under the Apache License, Version 2.0 (the "License");
1718package org .testingisdocumenting .webtau .cache ;
1819
1920import org .testingisdocumenting .webtau .cfg .WebTauConfig ;
21+ import org .testingisdocumenting .webtau .reporter .StepReportOptions ;
22+ import org .testingisdocumenting .webtau .reporter .WebTauStep ;
23+
24+ import static org .testingisdocumenting .webtau .reporter .IntegrationTestsMessageBuilder .*;
25+ import static org .testingisdocumenting .webtau .reporter .IntegrationTestsMessageBuilder .stringValue ;
26+ import static org .testingisdocumenting .webtau .reporter .TokenizedMessage .tokenizedMessage ;
2027
2128public class Cache {
2229 public static final Cache cache = new Cache ();
@@ -27,15 +34,29 @@ private Cache() {
2734 fileBasedCache = new FileBasedCache (() -> WebTauConfig .getCfg ().getCachePath ());
2835 }
2936
37+ public <E > CachedValue <E > value (String id ) {
38+ return new CachedValue <>(cache , id );
39+ }
40+
3041 public <E > E get (String key ) {
31- return fileBasedCache .get (key );
42+ WebTauStep step = WebTauStep .createStep (null ,
43+ tokenizedMessage (action ("getting cached value" ), FROM , id (key )),
44+ (r ) -> tokenizedMessage (action ("got cached value" ), FROM , id (key ), COLON , stringValue (r )),
45+ () -> fileBasedCache .get (key ));
46+
47+ return step .execute (StepReportOptions .SKIP_START );
3248 }
3349
3450 public void put (String key , Object value , long expirationTime ) {
35- fileBasedCache .put (key , value , expirationTime );
51+ WebTauStep step = WebTauStep .createStep (null ,
52+ tokenizedMessage (action ("caching value" ), AS , id (key ), COLON , stringValue (value )),
53+ () -> tokenizedMessage (action ("cached value" ), AS , id (key ), COLON , stringValue (value )),
54+ () -> fileBasedCache .put (key , value , expirationTime ));
55+
56+ step .execute (StepReportOptions .SKIP_START );
3657 }
3758
3859 public void put (String key , Object value ) {
39- fileBasedCache . put (key , value );
60+ put (key , value , Long . MAX_VALUE );
4061 }
4162}
0 commit comments