Tabnine Logo
VCacheFactory
Code IndexAdd Tabnine to your IDE (free)

How to use
VCacheFactory
in
com.atlassian.vcache

Best Java code snippets using com.atlassian.vcache.VCacheFactory (Showing top 20 results out of 315)

origin: com.atlassian.confluence.extra.widgetconnector/widgetconnector

private StableReadExternalCache<String> getCache(String cacheName) {
  return cacheFactory.getStableReadExternalCache(
      cacheName, serializableMarshaller(String.class), new ExternalCacheSettingsBuilder().build()
  );
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test-utils

/**
 * Build {@link DirectExternalCache} and set up mockito expectations for appropriate calls of {@link VCacheFactory}
 *
 * @param mockVcacheFactory mockito proxied or mocked {@link VCacheFactory}
 * @param name name of the cache
 * @param clazz class of cached objects
 * @param settings cache settings
 * @param <T> type of cached objects
 * @return {@link DirectExternalCache} proxied by mockito.
 */
public static <T extends Serializable> DirectExternalCache<T> getExternalCache(VCacheFactory mockVcacheFactory,
                                        String name, Class<T> clazz,
                                        ExternalCacheSettings settings) {
  final DirectExternalCache<T> desiredCache = spy(mockVcacheFactory.getDirectExternalCache(name,
      JavaSerializationMarshalling.pair(clazz), settings));
  doReturn(desiredCache).when(mockVcacheFactory).getDirectExternalCache(eq(name), any(MarshallingPair.class),
      any(ExternalCacheSettings.class));
  return desiredCache;
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test-utils

/**
 * Build {@link JvmCache} and set up mockito expectations for appropriate calls of {@link VCacheFactory}
 *
 * @param mockVcacheFactory mockito proxied or mocked {@link VCacheFactory}
 * @param cacheName name of the cache
 * @param settings cache settings
 * @param <K> type of cache keys
 * @param <V> type of cached objects
 * @return {@link JvmCache} proxied by mockito.
 */
public static <K, V> JvmCache<K, V> getJvmCache(VCacheFactory mockVcacheFactory, String cacheName,
                        JvmCacheSettings settings) {
  final JvmCache<K, V> desiredCache = spy(mockVcacheFactory.getJvmCache(cacheName, settings));
  doReturn(desiredCache).when(mockVcacheFactory).getJvmCache(eq(cacheName), any(JvmCacheSettings.class));
  return desiredCache;
}
origin: com.atlassian.plugins/atlassian-connect-core

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();
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void duplicate_names_different_policys() {
  final DirectExternalCache<String> directCache =
      vCacheFactory().getDirectExternalCache(
          "duplicate", StringMarshalling.pair(), new ExternalCacheSettingsBuilder().build());
  thrown.expect(ExternalCacheException.class);
  thrown.expectMessage("Failed due to CREATION_FAILURE");
  final StableReadExternalCache<String> stableCache =
      vCacheFactory().getStableReadExternalCache(
          "duplicate", StringMarshalling.pair(), new ExternalCacheSettingsBuilder().build());
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test-utils

/**
 * Build {@link TransactionalExternalCache} and set up mockito expectations for appropriate calls of {@link VCacheFactory}
 *
 * @param mockVcacheFactory mockito proxied or mocked {@link VCacheFactory}
 * @param name name of the cache
 * @param clazz class of cached objects
 * @param settings cache settings
 * @param <T> type of cached objects
 * @return {@link TransactionalExternalCache} proxied by mockito.
 */
public static <T extends Serializable> TransactionalExternalCache<T> getTransactionalCache(VCacheFactory mockVcacheFactory,
                                              String name, Class<T> clazz,
                                              ExternalCacheSettings settings) {
  final TransactionalExternalCache<T> desiredCache = spy(mockVcacheFactory.getTransactionalExternalCache(name,
      JavaSerializationMarshalling.pair(clazz), settings));
  doReturn(desiredCache).when(mockVcacheFactory).getTransactionalExternalCache(eq(name), any(MarshallingPair.class),
      any(ExternalCacheSettings.class));
  return desiredCache;
}
origin: com.atlassian.plugins/atlassian-connect-core

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);
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void transactionalExternalCache_normal_marshalling() {
  final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder()
      .defaultTtl(Duration.ofSeconds(60))
      .entryGrowthRateHint(ChangeRate.LOW_CHANGE)
      .dataChangeRateHint(ChangeRate.LOW_CHANGE)
      .entryCountHint(100)
      .build();
  final TransactionalExternalCache<String> cache = vCacheFactory().getTransactionalExternalCache(
      "my-txn-cache", StringMarshalling.pair(), settings);
  assertThat(cache, notNullValue());
  assertThat(cache.getName(), is("my-txn-cache"));
  assertThat(invocationsOfBegunTxns, is(0));
  cache.removeAll();
  assertThat(invocationsOfBegunTxns, is(1));
  cache.put("three", "drei", PUT_ALWAYS);
  final CompletionStage<Optional<String>> get1 = cache.get("three");
  assertThat(get1, successfulWith(is(Optional.of("drei"))));
  vCacheLifecycleManager().transactionSync(currentRequestContext());
  assertThat(invocationsOfBegunTxns, is(1));
  forceNewRequestContext();
  final CompletionStage<Optional<String>> get2 = cache.get("three");
  assertThat(invocationsOfBegunTxns, is(2));
  unsafeJoin(get2.toCompletableFuture()).get();
  assertThat(get2, successfulWith(is(Optional.of("drei"))));
  assertThat(invocationsOfBegunTxns, is(2));
}
origin: com.atlassian.confluence.plugins/confluence-masterdetail-plugin

@SuppressWarnings("unchecked")
private StableReadExternalCache<ImmutableMap<String, ImmutableList<ImmutableMap<String, PageProperty>>>> createCache(VCacheFactory cacheFactory) {
  return cacheFactory.getStableReadExternalCache(
      CACHE_NAME,
      (Marshaller) serializableMarshaller(ImmutableMap.class),
      new ExternalCacheSettingsBuilder().build()
  );
}
origin: com.atlassian.plugins/atlassian-connect-core

@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));
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void transactionalExternalCache_normal_marshaller() {
  final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder()
      .defaultTtl(Duration.ofSeconds(60))
      .entryGrowthRateHint(ChangeRate.LOW_CHANGE)
      .dataChangeRateHint(ChangeRate.LOW_CHANGE)
      .entryCountHint(100)
      .build();
  @SuppressWarnings("deprecation")
  final TransactionalExternalCache<String> cache = vCacheFactory().getTransactionalExternalCache(
      "my-txn-cache", MarshallerFactory.stringMarshaller(), settings);
  assertThat(cache, notNullValue());
  assertThat(cache.getName(), is("my-txn-cache"));
  assertThat(invocationsOfBegunTxns, is(0));
  cache.removeAll();
  assertThat(invocationsOfBegunTxns, is(1));
  cache.put("three", "drei", PUT_ALWAYS);
  final CompletionStage<Optional<String>> get1 = cache.get("three");
  assertThat(get1, successfulWith(is(Optional.of("drei"))));
  vCacheLifecycleManager().transactionSync(currentRequestContext());
  assertThat(invocationsOfBegunTxns, is(1));
  forceNewRequestContext();
  final CompletionStage<Optional<String>> get2 = cache.get("three");
  assertThat(invocationsOfBegunTxns, is(2));
  unsafeJoin(get2.toCompletableFuture()).get();
  assertThat(get2, successfulWith(is(Optional.of("drei"))));
  assertThat(invocationsOfBegunTxns, is(2));
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void directexternalcache_duplicate_obtain() {
  final DirectExternalCache<String> firstTime =
      vCacheFactory().getDirectExternalCache(
          "duplicate", dodgyPair("first"), new ExternalCacheSettingsBuilder().build());
  final CompletionStage<Boolean> put1 = firstTime.put("key", "ignored", PUT_ALWAYS);
  assertThat(VCacheUtils.unsafeJoin(put1), is(true));
  final CompletionStage<Optional<String>> get1 = firstTime.get("key");
  assertThat(VCacheUtils.unsafeJoin(get1), is(Optional.of("first")));
  final DirectExternalCache<String> secondTime =
      vCacheFactory().getDirectExternalCache(
          "duplicate", dodgyPair("second"), new ExternalCacheSettingsBuilder().build());
  final CompletionStage<Optional<String>> get2 = secondTime.get("key");
  assertThat(VCacheUtils.unsafeJoin(get2), is(Optional.of("second")));
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

    .build();
final JvmCache<String, Long> cache = vCacheFactory().getJvmCache("my-jvm-cache", settings);
origin: com.atlassian.confluence.extra.widgetconnector/widgetconnector

public TwitterRenderer(I18NBeanFactory i18NBeanFactory, LocaleManager localeManager, VCacheFactory cacheFactory, PageBuilderService pageBuilderService, VelocityRenderService velocityRenderService, HttpRetrievalService httpRetrievalService) {
  this.i18NBeanFactory = i18NBeanFactory;
  this.localeManager = localeManager;
  this.pageBuilderService = pageBuilderService;
  this.velocityRenderService = velocityRenderService;
  this.httpRetrievalService = httpRetrievalService;
  this.cacheRef = Lazy.supplier(() -> cacheFactory.getStableReadExternalCache(
      CACHE_NAME,
      serializableMarshaller(TweetRetrievalResult.class),
      new ExternalCacheSettingsBuilder().build()
  ));
}
origin: com.atlassian.plugins/atlassian-connect-core

@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();
  }
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void txnexternalcache_duplicate_obtain() {
  final TransactionalExternalCache<String> firstTime =
      vCacheFactory().getTransactionalExternalCache(
          "duplicate", dodgyPair("first"), new ExternalCacheSettingsBuilder().build());
  firstTime.put("key", "ignored", PUT_ALWAYS);
  vCacheLifecycleManager().transactionSync(currentRequestContext());
  forceNewRequestContext();
  final CompletionStage<Optional<String>> get1 = firstTime.get("key");
  assertThat(VCacheUtils.unsafeJoin(get1), is(Optional.of("first")));
  final TransactionalExternalCache<String> secondTime =
      vCacheFactory().getTransactionalExternalCache(
          "duplicate", dodgyPair("second"), new ExternalCacheSettingsBuilder().build());
  forceNewRequestContext();
  final CompletionStage<Optional<String>> get2 = secondTime.get("key");
  assertThat(VCacheUtils.unsafeJoin(get2), is(Optional.of("second")));
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void directExternalCache_normal_marshalling() {
  final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder()
      .defaultTtl(Duration.ofSeconds(60))
      .entryGrowthRateHint(ChangeRate.LOW_CHANGE)
      .dataChangeRateHint(ChangeRate.LOW_CHANGE)
      .entryCountHint(100)
      .build();
  final DirectExternalCache<String> cache = vCacheFactory().getDirectExternalCache(
      "my-direct-cache", StringMarshalling.pair(), settings);
  assertThat(cache, notNullValue());
  assertThat(cache.getName(), is("my-direct-cache"));
  final CompletionStage<Void> rmall = cache.removeAll();
  assertThat(rmall, successful());
  final CompletionStage<Boolean> put1 = cache.put("one", "eine", PUT_ALWAYS);
  assertThat(put1, successfulWith(is(true)));
  final CompletionStage<Optional<String>> get1 = cache.get("one");
  assertThat(get1, successfulWith(is(Optional.of("eine"))));
  assertThat(vCacheManagement().allJvmCacheDetails().size(), is(0));
  assertThat(vCacheManagement().allRequestCacheDetails().size(), is(0));
  final Map<String, ExternalCacheDetails> allCacheDetails = vCacheManagement().allExternalCacheDetails();
  assertThat(allCacheDetails, notNullValue());
  assertThat(allCacheDetails.keySet(), containsInAnyOrder("my-direct-cache"));
  final ExternalCacheDetails cacheDetails = allCacheDetails.get("my-direct-cache");
  assertThat(cacheDetails.getName(), is("my-direct-cache"));
  assertThat(cacheDetails.getSettings().getDefaultTtl(), is(Optional.of(MAX_TTL)));
  assertThat(cacheDetails.getSettings().getEntryCountHint(), is(Optional.of(MAX_ENTRIES)));
  assertThat(invocationsOfBegunTxns, is(0));
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

@Test
public void stablereadexternalcache_duplicate_obtain() {
  final StableReadExternalCache<String> firstTime =
      vCacheFactory().getStableReadExternalCache(
          "duplicate", dodgyPair("first"), new ExternalCacheSettingsBuilder().build());
  final CompletionStage<Boolean> put1 = firstTime.put("key", "ignored", PUT_ALWAYS);
  assertThat(VCacheUtils.unsafeJoin(put1), is(true));
  forceNewRequestContext();
  final CompletionStage<Optional<String>> get1 = firstTime.get("key");
  assertThat(VCacheUtils.unsafeJoin(get1), is(Optional.of("first")));
  final StableReadExternalCache<String> secondTime =
      vCacheFactory().getStableReadExternalCache(
          "duplicate", dodgyPair("second"), new ExternalCacheSettingsBuilder().build());
  forceNewRequestContext();
  final CompletionStage<Optional<String>> get2 = secondTime.get("key");
  assertThat(VCacheUtils.unsafeJoin(get2), is(Optional.of("second")));
}
origin: com.atlassian.plugins/atlassian-connect-core

@Override
public Optional<String> getDescriptor(@Nonnull final String addonKey) {
  return vCacheRequestFactory.<String, Optional<String>>getRequestCache(DESCRIPTORS_REQUEST_CACHE_KEY).get(addonKey, () -> databaseConnectAddonDescriptorsPersister.getDescriptor(addonKey));
}
origin: com.atlassian.vcache/atlassian-vcache-internal-test

    .build();
final TransactionalExternalCache<String> cache1 = vCacheFactory().getTransactionalExternalCache(
    "sync_sync_sync-1", StringMarshalling.pair(), settings);
assertThat(invocationsOfBegunTxns, is(0));
assertThat(invocationsOfBegunTxns, is(1));
final TransactionalExternalCache<String> cache2 = vCacheFactory().getTransactionalExternalCache(
    "sync_sync_sync-2", StringMarshalling.pair(), settings);
assertThat(invocationsOfBegunTxns, is(2));
final TransactionalExternalCache<String> cache3 = vCacheFactory().getTransactionalExternalCache(
    "sync_sync_sync-3", StringMarshalling.pair(), settings);
com.atlassian.vcacheVCacheFactory

Javadoc

Represents the factory for creating caches.

Notes:

  • JvmCache's and RequestCache's are identified by their name and cache type. I.e. A JvmCache called 'Williams' and a RequestCache called 'Williams' are considered to be separate caches.
  • ExternalCache's are identified by their name and cache type.
  • A cache name may only contain the characters A-Z, a-z, 0-9, ./-_$.
  • The returned cache instances are multi-thread safe.

Most used methods

  • getStableReadExternalCache
    Obtains a StableReadExternalCache with the specified details. Note: each call to this method will re
  • getDirectExternalCache
    Obtains a DirectExternalCache with the specified details. Note: each call to this method will return
  • getJvmCache
    Obtains a JvmCache with the specified details. Note: multiple calls to this method will always retur
  • getRequestCache
    Obtains a RequestCache with the specified details. Note: multiple calls to this method will always r
  • getTransactionalExternalCache
    Obtains a TransactionalExternalCache with the specified details. Note: each call to this method will

Popular in Java

  • Parsing JSON documents to java classes using gson
  • runOnUiThread (Activity)
  • getContentResolver (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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