@Test public void invalidate_whenNotPresent() { final Storage storage = mock( Storage.class ); final WebStorageCacheService service = new WebStorageCacheService( storage ); final ChannelAddress address = newAddress(); when( storage.getItem( WebStorageCacheService.ETAG_INDEX + '-' + address.getSystemId() ) ).thenReturn( null ); assertFalse( service.invalidate( address ) ); verify( storage ).getItem( WebStorageCacheService.ETAG_INDEX + '-' + address.getSystemId() ); }
@Override public boolean invalidate( @Nonnull final ChannelAddress address ) { Objects.requireNonNull( address ); final int systemId = address.getSystemId(); final JsPropertyMap<String> index = findIndex( systemId ); final String key = address.asChannelDescriptor(); if ( null == index || null == index.get( key ) ) { return false; } else { index.delete( key ); saveIndex( systemId, index ); getStorage().removeItem( address.getCacheKey() ); return true; } }
WebStorageCacheService implements CacheService { @Override public boolean invalidate( @Nonnull final ChannelAddress address ) { Objects.requireNonNull( address ); final int systemId = address.getSystemId(); final JsPropertyMap<String> index = findIndex( systemId ); final String key = address.asChannelDescriptor(); if ( null == index || null == index.get( key ) ) { return false; } else { index.delete( key ); saveIndex( systemId, index ); getStorage().removeItem( address.getCacheKey() ); return true; } } }
WebStorageCacheService implements CacheService { @Override public boolean invalidate( @Nonnull final ChannelAddress address ) { Objects.requireNonNull( address ); final int systemId = address.getSystemId(); final JsPropertyMap<String> index = findIndex( systemId ); final String key = address.asChannelDescriptor(); if ( null == index || null == index.get( key ) ) { return false; } else { index.delete( key ); saveIndex( systemId, index ); getStorage().removeItem( address.getCacheKey() ); return true; } } WebStorageCacheService( @Nonnull final Storage storage ); }
WebStorageCacheService implements CacheService { @Override public boolean invalidate( @Nonnull final ChannelAddress address ) { Objects.requireNonNull( address ); final int systemId = address.getSystemId(); final JsPropertyMap<String> index = findIndex( systemId ); final String key = address.asChannelDescriptor(); if ( null == index || null == index.get( key ) ) { return false; } else { index.delete( key ); saveIndex( systemId, index ); getStorage().removeItem( address.getCacheKey() ); return true; } } WebStorageCacheService( @Nonnull final Storage storage ); static boolean isSupported(); static boolean isSupported( @Nonnull final Window window ); static void install(); static void install( @Nonnull final ReplicantContext context ); static void install( @Nonnull final Window window ); static void install( @Nonnull final ReplicantContext context, @Nonnull final Window window ); static void install( @Nonnull final Storage storage ); static void install( @Nonnull final ReplicantContext context, @Nonnull final Storage storage ); @Nonnull @Override Set<ChannelAddress> keySet( final int systemId ); @Nullable @Override String lookupEtag( @Nonnull final ChannelAddress address ); @Nullable @Override CacheEntry lookup( @Nonnull final ChannelAddress address ); @Override boolean store( @Nonnull final ChannelAddress address,
                        @Nonnull final String eTag,
                        @Nonnull final String content ); @Override boolean invalidate( @Nonnull final ChannelAddress address ); }
WebStorageCacheService implements CacheService { @Override public boolean invalidate( @Nonnull final ChannelAddress address ) { Objects.requireNonNull( address ); final int systemId = address.getSystemId(); final JsPropertyMap<String> index = findIndex( systemId ); final String key = address.asChannelDescriptor(); if ( null == index || null == index.get( key ) ) { return false; } else { index.delete( key ); saveIndex( systemId, index ); getStorage().removeItem( address.getCacheKey() ); return true; } } WebStorageCacheService( @Nonnull final Storage storage ); static boolean isSupported(); static boolean isSupported( @Nonnull final Window window ); static void install(); static void install( @Nonnull final ReplicantContext context ); static void install( @Nonnull final Window window ); static void install( @Nonnull final ReplicantContext context, @Nonnull final Window window ); static void install( @Nonnull final Storage storage ); static void install( @Nonnull final ReplicantContext context, @Nonnull final Storage storage ); @Nonnull @Override Set<ChannelAddress> keySet( final int systemId ); @Nullable @Override String lookupEtag( @Nonnull final ChannelAddress address ); @Nullable @Override CacheEntry lookup( @Nonnull final ChannelAddress address ); @Override boolean store( @Nonnull final ChannelAddress address,
                        @Nonnull final String eTag,
                        @Nonnull final String content ); @Override boolean invalidate( @Nonnull final ChannelAddress address );  }