protected void invalidateCache() { vCacheRequestFactory.getRequestCache(DESCRIPTORS_REQUEST_CACHE_KEY).removeAll(); vCacheRequestFactory.getRequestCache(REQUEST_CACHE_KEY).removeAll(); vCacheRequestFactory.getRequestCache(REMNANTS_REQUEST_CACHE_KEY).removeAll(); vCacheRequestFactory.getRequestCache(SHALLOW_BEAN_REQUEST_CACHE_KEY).removeAll(); }
protected void invalidateCache(String addonKey) { vCacheRequestFactory.getRequestCache(DESCRIPTORS_REQUEST_CACHE_KEY).remove(addonKey); vCacheRequestFactory.getRequestCache(REQUEST_CACHE_KEY).remove(addonKey); vCacheRequestFactory.getRequestCache(REMNANTS_REQUEST_CACHE_KEY).remove(addonKey); vCacheRequestFactory.getRequestCache(SHALLOW_BEAN_REQUEST_CACHE_KEY).remove(addonKey); }
@Autowired public ConnectDynamicModuleProvider( final VertigoState vertigoState, @ComponentImport final DynamicModuleProviderRegistrar dynamicModuleProviderRegistrar, final ConnectPluginModuleDeserializerRegistry connectPluginModuleDeserializerRegistry, final TenantPluginModulesManager tenantPluginModulesManager, final PluginRetrievalService pluginRetrievalService, final VCacheFactory vCacheFactory, final EventPublisher eventPublisher) { this.vertigoState = vertigoState; this.dynamicModuleProviderRegistrar = dynamicModuleProviderRegistrar; this.connectPluginModuleDeserializerRegistry = connectPluginModuleDeserializerRegistry; this.tenantPluginModulesManager = tenantPluginModulesManager; this.pluginRetrievalService = pluginRetrievalService; this.eventPublisher = eventPublisher; requestPluginModulesByIdentifierReference = vCacheFactory.getRequestCache("com.atlassian.connect.module-provider.plugin-modules-by-identifier." + TenantPluginModuleProtos.PluginModuleCollection.class.hashCode()); requestModuleDescriptorsForDeserializerReference = vCacheFactory.getRequestCache("com.atlassian.connect.module-provider.module-descriptors-for-deserializer"); requestModuleVersionTracker = new ImmutableWorkContextReference<>(() -> new AtomicInteger(-1)); }
@Override public Optional<byte[]> getStoredData() { final Lock dataLock = requestLock.get(); // This lock ensures that the supplier for the stored data only gets called once. Ensuring that we only access the db once. dataLock.lock(); try { return vCacheFactory.<String, Optional<byte[]>>getRequestCache(STORED_REQUEST_CACHE_KEY).get(STORED_REQUEST_CACHE_DATA, storedDataRetriever); } finally { dataLock.unlock(); } }
@Override public Optional<String> getDescriptor(@Nonnull final String addonKey) { return vCacheRequestFactory.<String, Optional<String>>getRequestCache(DESCRIPTORS_REQUEST_CACHE_KEY).get(addonKey, () -> databaseConnectAddonDescriptorsPersister.getDescriptor(addonKey)); }
public ConnectAddonBean fromJson(final String jsonDescriptor) throws InvalidDescriptorException { // Important: This unique name is an attempt to get a different cache after a P2 plugin reinstall on the Atlassian Connect plugin // like you would expect to see in development. This is required because the ConnectAddonBean class will be different before and // after a P2 plugin reinstall and thus you will get a class cast exception like this: https://bitbucket.org/snippets/atlassian/44Bkz final String jsonDescriptorLookupKey = jsonDescriptor + "." + ConnectAddonBean.class.hashCode(); return vCacheRequestFactory.<String, ConnectAddonBean>getRequestCache(REQUEST_CACHE_KEY).get(jsonDescriptorLookupKey, () -> ConnectAddonBeanFactory.this.fromJsonImpl(jsonDescriptor) ); }
private String processSegment(String location, ConnectAddonBean addon) { final RequestCache<ConnectAddonBean, Map<String, String>> requestCache = vCacheRequestFactory.getRequestCache(REQUEST_CACHE_KEY); return requestCache.get(addon, () -> buildKeyMap(addon)).getOrDefault(location,location); }
protected Optional<RawConnectAddon> getAddonWithCaching(@Nonnull final String addonKey) { return vCacheRequestFactory.<String, Optional<RawConnectAddon>>getRequestCache(REQUEST_CACHE_KEY).get(addonKey, () -> databaseConnectAddonPersister.getConnectAddon(addonKey)); }
protected Optional<RawConnectAddonRemnant> getRemnantWithCaching(@Nonnull final String addonKey) { return vCacheRequestFactory.<String, Optional<RawConnectAddonRemnant>>getRequestCache(REMNANTS_REQUEST_CACHE_KEY).get(addonKey, () -> databaseConnectAddonPersister.getRemnant(addonKey)); }
@Override public Optional<ShallowConnectAddon> getShallowAddon(String addonKey) { return vCacheRequestFactory.<String, Optional<ShallowConnectAddon>>getRequestCache(SHALLOW_BEAN_REQUEST_CACHE_KEY).get(addonKey, () -> shallowAddonDBConstructor(addonKey)); }
@Override public RemotablePluginAccessor get(final String pluginKey) { return vCacheFactory.<String, RemotablePluginAccessor>getRequestCache(ACCESSOR_BY_KEY_REQUEST_CACHE).get(pluginKey, () -> { final Optional<ShallowConnectAddon> optionalAddon = addonAccessor.getShallowAddonEfficiently(pluginKey); if (optionalAddon.isPresent()) { return RemotablePluginAccessorFactoryImpl.this.get(optionalAddon.get()); } final Plugin plugin = pluginAccessor.getPlugin(pluginKey); return RemotablePluginAccessorFactoryImpl.this.get(plugin, pluginKey, optionalAddon); }); }
@Override public void restoreAddonRemnant(@Nonnull final String addonKey, Optional<String> maybeOldSecretToRestore, Optional<String> maybeOldOAuthClient) { final RdbmsSchema rdbmsSchema = rdbmsSchemaService.get(); // RDBMS execute wants us to return it something. So here we are returning a boolean no one cares about. rdbmsSchema.getFactory().create().execute(connection -> { final PostgreSQLQueryFactory queryFactory = new PostgreSQLQueryFactory(() -> connection); RawConnectAddonRemnant remnant = new RawConnectAddonRemnant(addonKey, maybeOldSecretToRestore.orElse(null), maybeOldOAuthClient.orElse(null)); databaseConnectAddonPersister.rollbackRemnant(queryFactory, remnant); return true; }); vCacheRequestFactory.<String, Optional<RawConnectAddonRemnant>>getRequestCache(REMNANTS_REQUEST_CACHE_KEY).remove(addonKey); }
@Test public void requestCache_normal() { final RequestCache<String, String> cache = vCacheFactory().getRequestCache("my-request-cache"); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-request-cache")); cache.removeAll(); cache.put("one", "eine"); final Optional<String> get1 = cache.get("one"); assertThat(get1, is(Optional.of("eine"))); assertThat(vCacheManagement().allJvmCacheDetails().size(), is(0)); assertThat(vCacheManagement().allExternalCacheDetails().size(), is(0)); final Map<String, RequestCacheDetails> allCacheDetails = vCacheManagement().allRequestCacheDetails(); assertThat(allCacheDetails, notNullValue()); assertThat(allCacheDetails.keySet(), containsInAnyOrder("my-request-cache")); final RequestCacheDetails cacheDetails = allCacheDetails.get("my-request-cache"); assertThat(cacheDetails.getName(), is("my-request-cache")); assertThat(invocationsOfBegunTxns, is(0)); }
@Override public void storeRestartState(@Nonnull final String addonKey, PluginState state) { final RdbmsSchema rdbmsSchema = rdbmsSchemaService.get(); rdbmsSchema.getFactory().create().execute(connection -> { final PostgreSQLQueryFactory queryFactory = new PostgreSQLQueryFactory(() -> connection); databaseConnectAddonPersister.storeState(queryFactory, addonKey, state); // This return is useless and only here to keep compiler happy. return true; }); vCacheRequestFactory.<String, Optional<RawConnectAddon>>getRequestCache(REQUEST_CACHE_KEY).remove(addonKey); }
vCacheFactory.<String, Optional<byte[]>>getRequestCache(STORED_REQUEST_CACHE_KEY).removeAll();