Java 8 ha raggiunto la fine del supporto
e verrà ritirato
il 31 gennaio 2026. Dopo il ritiro, non potrai eseguire il deployment di applicazioni Java 8, anche se la tua organizzazione ha utilizzato in precedenza un criterio dell'organizzazione per riattivare i deployment di runtime legacy. Le tue applicazioni Java 8 esistenti continueranno a essere eseguite e a ricevere traffico dopo la
data di ritiro. Ti consigliamo di eseguire la migrazione all'ultima versione supportata di Java.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina fornisce esempi di codice in Java per l'utilizzo dell'API Memcache di basso livello. Memcache
è un sistema distribuito ad alte prestazioni per il caching di oggetti in memoria che fornisce
rapido accesso ai dati memorizzati nella cache. Per saperne di più su Memcache, consulta la
panoramica di Memcache.
Utilizzo sincrono
Esempio di API di basso livello che utilizza MemcacheService sincrono:
@SuppressWarnings("serial")// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.@WebServlet(name="MemcacheSync",description="Memcache: Synchronous",urlPatterns="/memcache/sync")publicclassMemcacheSyncCacheServletextendsHttpServlet{@OverridepublicvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsIOException,ServletException{Stringpath=req.getRequestURI();if(path.startsWith("/favicon.ico")){return;// ignore the request for favicon.ico}MemcacheServicesyncCache=MemcacheServiceFactory.getMemcacheService();syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));Stringkey="count-sync";byte[]value;longcount=1;value=(byte[])syncCache.get(key);if(value==null){value=BigInteger.valueOf(count).toByteArray();syncCache.put(key,value);}else{// Increment valuecount=newBigInteger(value).longValue();count++;value=BigInteger.valueOf(count).toByteArray();// Put back in cachesyncCache.put(key,value);}// Output contentresp.setContentType("text/plain");resp.getWriter().print("Value is "+count+"\n");}}
Utilizzo asincrono
Esempio di API di basso livello che utilizza AsyncMemcacheService:
AsyncMemcacheServiceasyncCache=MemcacheServiceFactory.getAsyncMemcacheService();asyncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));Stringkey="count-async";byte[]value;longcount=1;Future<Object>futureValue=asyncCache.get(key);// Read from cache.// ... Do other work in parallel to cache retrieval.try{value=(byte[])futureValue.get();if(value==null){value=BigInteger.valueOf(count).toByteArray();asyncCache.put(key,value);}else{// Increment valuecount=newBigInteger(value).longValue();count++;value=BigInteger.valueOf(count).toByteArray();// Put back in cacheasyncCache.put(key,value);}}catch(InterruptedException|ExecutionExceptione){thrownewServletException("Error when waiting for future value",e);}
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-19 UTC."],[[["\u003cp\u003eThis page offers Java code examples for utilizing the low-level Memcache API, which is a high-speed, distributed memory caching system for efficient data access.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code demonstrates both synchronous usage with \u003ccode\u003eMemcacheService\u003c/code\u003e and asynchronous usage with \u003ccode\u003eAsyncMemcacheService\u003c/code\u003e for interacting with the cache.\u003c/p\u003e\n"],["\u003cp\u003eThis legacy bundled API is exclusive to first-generation runtimes within the App Engine standard environment, and migration to newer Java environments like Java 11/17 requires review of the provided migration guide.\u003c/p\u003e\n"],["\u003cp\u003eThe examples show how to get, set and increment values in the cache, demonstrating basic operations using the Memcache API.\u003c/p\u003e\n"]]],[],null,[]]