Usa Memcache
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta página, se describe cómo configurar y supervisar el servicio de Memcache para tu aplicación con la consola de Google Cloud . También se explica cómo usar la API para PHP de Memcache de App Engine a fin de configurar y recuperar valores almacenados en caché. Para obtener más información sobre Memcache, consulta la Descripción general de Memcache.
Configura Memcache
- Ve a la página de Memcache en la Google Cloud consola.
Ir a la página de Memcache
Selecciona el nivel de servicio de Memcache que desees usar:
- Compartido (predeterminado): es gratuito y proporciona capacidades de caché sobre la base del "mejor esfuerzo".
- Dedicado: se factura por GB por hora de tamaño de caché y proporciona una capacidad de caché fija asignada exclusivamente a tu aplicación.
Puedes aprender más sobre clases de servicio disponibles en Descripción general de Memcache.
Cómo almacenar valores en caché y recuperarlos
Almacena un valor en caché
Usa Memcache::set
para agregar el valor de una clave:
Busca valores almacenados en caché
Usa Memcache::get
para buscar el valor de una sola clave:
Supervisa Memcache en la Google Cloud consola
- Ve a la página de Memcache en la Google Cloud consola.
Ir a la página de Memcache
- Consulta los siguientes informes:
- Nivel de servicio de Memcache: Muestra si tu aplicación usa el nivel de servicio Compartido o Dedicado.
Si eres propietario del proyecto, puedes alternar entre ambos. Obtén más información sobre los niveles de servicio.
- Proporción de aciertos: Muestra el porcentaje de solicitudes de datos que se entregaron desde la caché y la cantidad de solicitudes de datos sin procesar que se entregaron desde la caché.
- Elementos en la caché.
- Edad del elemento más antiguo: Edad del elemento almacenado en caché más antiguo. Ten en cuenta que la edad de un elemento se restablece cada vez que se usa, ya sea en operaciones de lectura o de escritura.
- Tamaño total de caché
Puedes realizar cualquiera de las siguientes acciones:
- Clave nueva: agrégale una clave a la caché.
- Encontrar una clave: recupera una clave existente.
- Limpiar caché: quita todos los pares clave-valor de la caché.
(Solo para Memcache dedicada) Consulta la lista de claves populares.
- Las "claves populares" son claves que reciben más de 100 consultas por segundo (QPS) en Memcache.
- La lista incluye hasta 100 claves populares ordenadas de mayor a menor cantidad de QPS.
¿Qué sigue?
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-09-04 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThis page guides users on configuring and monitoring the memcache service for applications using the Google Cloud console, as well as utilizing the App Engine Memcache PHP API for caching.\u003c/p\u003e\n"],["\u003cp\u003eMemcache offers two service levels, Shared and Dedicated, with the former being free and the latter providing a fixed, billed cache capacity.\u003c/p\u003e\n"],["\u003cp\u003eUsers can cache values using \u003ccode\u003eMemcache::set\u003c/code\u003e and retrieve cached values using \u003ccode\u003eMemcache::get\u003c/code\u003e via the App Engine Memcache PHP API.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud console allows for monitoring of the memcache service level, hit ratio, cache items, oldest item age, and total cache size, and offers actions like adding, finding, or flushing keys.\u003c/p\u003e\n"],["\u003cp\u003eDedicated memcache provides a hot key list for keys that receives more than 100 queries per second.\u003c/p\u003e\n"]]],[],null,["# Using Memcache\n\nThis page describes how to configure and monitor the memcache service for your\napplication using the Google Cloud console. It also describes how to use the\nApp Engine Memcache PHP API to set and retrieve cached values. To learn more about memcache,\nread the [Memcache Overview](/appengine/docs/legacy/standard/php/memcache).\n\n\u003cbr /\u003e\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| php-gen2\n|\n| /services/access). If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\nConfiguring memcache\n--------------------\n\n1. Go to the Memcache page in the Google Cloud console. \n [Go to the Memcache page](https://console.cloud.google.com/appengine/memcache)\n2. Select the memcache service level you want to use:\n\n - **Shared** (default) - free and provides cache capacity on a best-effort basis.\n - **Dedicated** - billed by the GB-hour of cache size and provides a fixed cache capacity assigned exclusively to your application.\n\n Learn more about available service classes in [Memcache Overview](#service_levels).\n\nCaching and retrieving values\n-----------------------------\n\n### Caching a value\n\nUse [`Memcache::set`](http://php.net/manual/en/memcache.set.php) to add a key's\nvalue: \n\n $memcache = new Memcache;\n $value = $request-\u003egetContent();\n return $memcache-\u003eset($key, $value);\n\n### Looking up cached values\n\nUse [`Memcache::get`](http://php.net/manual/en/memcache.get.php) to look up the\nvalue of a single key: \n\n $memcache = new Memcache;\n return $memcache-\u003eget($key);\n\nMonitoring memcache in the Google Cloud console\n-----------------------------------------------\n\n1. Go to the Memcache page in the Google Cloud console. \n [Go to the Memcache page](https://console.cloud.google.com/appengine/memcache) \n2. Look at the following reports:\n - **Memcache service level** : Shows if your application is using the Shared or Dedicated service level. If you are an owner of the project, you can switch between the two. Learn more about the [service levels](./#service_levels).\n - **Hit ratio**: Shows the percentage of data requests that were served from the cache, as well as the raw number of data requests that were served from the cache.\n - **Items in the cache**.\n - **Oldest item age**: The age of the oldest cached item. Note that the age of an item is reset every time it is used, either read or written.\n - **Total cache size**.\n3. You can take any of the following actions:\n\n - **New key**: Add a new key to the cache.\n - **Find a key**: Retrieve an existing key.\n - **Flush cache**: Remove all the key-value pairs from the cache.\n4. (Dedicated memcache only) Look through the list of **Hot keys**.\n\n - \"Hot keys\" are keys that receive more than 100 queries per second (QPS) in the memcache.\n - This list includes up to 100 hot keys, sorted by highest QPS.\n\nWhat's next\n-----------\n\n- Learn more about memcache in the [Memcache Overview](/appengine/docs/legacy/standard/php/memcache).\n- Refer to the documentation for the [Memcache](http://php.net/manual/en/book.memcache.php) and [Memcached](https://php.net/manual/en/book.memcached.php) APIs."]]