Go 1.11은 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Go 1.11 애플리케이션을 배포할 수 없습니다. 기존 Go 1.11 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 Go 버전으로 마이그레이션하는 것이 좋습니다.
Memcache 사용
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 Google Cloud 콘솔을 사용하여 애플리케이션에 Memcache 서비스를 구성하고 모니터링하는 방법을 설명합니다. 또한 App Engine memcache Go API를 사용하여 캐시된 값을 설정 및 검색하는 방법을 설명합니다. Memcache에 대한 자세한 내용은 Memcache 개요를 참조하세요.
Memcache 구성
- Google Cloud 콘솔에서 Memcache 페이지로 이동합니다.
Memcache 페이지로 이동
사용하려는 Memcache 서비스 수준을 선택합니다.
- 공유(기본값) - 가급적 최대한의 캐시 용량을 확보하여 제공합니다.
- 전용 - 캐시 크기의 GB 시간 단위로 요금이 청구되며, 애플리케이션 전용으로 할당되는 고정 캐시 용량을 제공합니다.
사용 가능한 서비스 등급에 대한 자세한 내용은 Memcache 개요를 참조하세요.
Go API 가져오기
memcache
패키지를 가져오려면 다음 안내를 따르세요.
값 캐싱 및 검색
값 캐싱
키 값이 없는 경우에만 Add()
를 사용하여 키 값을 작성합니다.
item := &memcache.Item{
Key: "[KEY]",
Value: []byte("[VALUE]"),
}
memcache.Add(c, item)
여기서 c
는 appengine.Context
입니다.
Memcache API 참조에서 Add
및 값 설정을 위한 기타 함수에 대해 자세히 알아보세요.
캐시된 값 조회
Get()
을 사용하여 특정 키의 항목을 가져옵니다.
memcache.Get(ctx, "[KEY]")
Memcache API 참조에서 Get
및 값을 검색하는 다른 함수에 대해 자세히 알아보세요.
예
다음 예시에서는 Go API를 사용하여 Memcache 값을 추가, 설정, 가져오는 방법을 보여줍니다.
ctx
가 appengine.Context
라고 가정합니다.
Google Cloud 콘솔에서 Memcache 모니터링
- Google Cloud 콘솔에서 Memcache 페이지로 이동합니다.
Memcache 페이지로 이동
- 다음 보고서를 확인합니다.
- Memcache 서비스 수준: 애플리케이션이 공유 서비스 수준을 사용하고 있는지 아니면 전용 서비스 수준을 사용하고 있는지를 표시합니다.
프로젝트 소유자는 두 수준 간에 전환할 수 있습니다. 자세한 내용은 서비스 수준을 참조하세요.
- 적중률: 캐시에서 제공된 데이터 요청의 비율과 더불어 캐시에서 제공된 데이터 요청의 총 개수를 보여줍니다.
- 캐시의 항목 수
- 가장 오래된 항목의 유지 기간: 가장 오래된 캐시된 항목의 유지 기간입니다. 항목의 유지 기간은 항목이 사용(읽기 또는 쓰기)될 때마다 재설정됩니다.
- 총 캐시 크기
다음과 같은 작업을 수행할 수 있습니다.
- 새 키: 캐시에 새 키를 추가합니다.
- 키 찾기: 기존 키를 검색합니다.
- 캐시 삭제: 캐시에서 모든 키-값 쌍을 삭제합니다.
(전용 Memcache에만 해당) 핫 키 목록을 살펴봅니다.
- '핫 키'는 Memcache에서 수신 QPS(초당 쿼리 수)가 100을 초과하는 키입니다.
- 이 목록에는 최대 100개의 핫 키가 QPS가 많은 순서대로 포함됩니다.
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThis guide outlines how to configure and monitor the memcache service for applications using the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003eThe document details how to utilize the App Engine memcache Go API to store and retrieve cached data through \u003ccode\u003eAdd()\u003c/code\u003e and \u003ccode\u003eGet()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMemcache offers two service levels: Shared, which is free with best-effort capacity, and Dedicated, which offers fixed cache capacity and is billed by GB-hour.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud console's Memcache page provides reports on service level, hit ratio, item count, item age, total cache size, and hot keys (for dedicated memcache).\u003c/p\u003e\n"],["\u003cp\u003eThe guide provides instructions on how to import the memcache package and provides a code example of adding, setting, and getting memcache values.\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 App Engine memcache Go API\nto set and retrieve cached values. To learn more about memcache,\nread the [Memcache Overview](/appengine/docs/legacy/standard/go111/memcache).\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| go\n| /services/access). If you are updating to the App Engine Go 1.12+ runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/go-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\nImporting the Go API\n--------------------\n\nTo import the `memcache` package: \n\n import \"google.golang.org/appengine/memcache\"\n\nCaching and retrieving values\n-----------------------------\n\n### Caching a value\n\nUse [`Add()`](/appengine/docs/legacy/standard/go111/reference/latest/memcache#google_golang_org_appengine_memcache_Add) to write a value for a key if and only if no value\nalready exists for the key: \n\n item := &memcache.Item{\n Key: \"[KEY]\",\n Value: []byte(\"[VALUE]\"),\n }\n memcache.Add(c, item)\n\nwhere `c` is an `appengine.Context`.\n\nLearn more about `Add` and other functions for setting values in [Memcache API\nReference](/appengine/docs/legacy/standard/go111/memcache/reference).\n\n### Looking up cached values\n\nUse [`Get()`](/appengine/docs/legacy/standard/go111/reference/latest/memcache#google_golang_org_appengine_memcache_Item_Get) to get the item for a given key: \n\n memcache.Get(ctx, \"[KEY]\")\n\nLearn more about `Get` and other functions for looking up values in [Memcache\nAPI Reference](/appengine/docs/legacy/standard/go111/memcache/reference).\n\n### Example\n\nThe following example demonstrates how to add, set, and get Memcache values\nusing the Go API.\n\nAssume that `ctx` is an `appengine.Context`. \n\n // Create an Item\n item := &memcache.Item{\n \tKey: \"lyric\",\n \tValue: []byte(\"Oh, give me a home\"),\n }\n // Add the item to the memcache, if the key does not already exist\n if err := memcache.Add(ctx, item); err == memcache.ErrNotStored {\n \tlog.Infof(ctx, \"item with key %q already exists\", item.Key)\n } else if err != nil {\n \tlog.Errorf(ctx, \"error adding item: %v\", err)\n }\n\n // Change the Value of the item\n item.Value = []byte(\"Where the buffalo roam\")\n // Set the item, unconditionally\n if err := memcache.Set(ctx, item); err != nil {\n \tlog.Errorf(ctx, \"error setting item: %v\", err)\n }\n\n // Get the item from the memcache\n if item, err := memcache.Get(ctx, \"lyric\"); err == memcache.ErrCacheMiss {\n \tlog.Infof(ctx, \"item not in the cache\")\n } else if err != nil {\n \tlog.Errorf(ctx, \"error getting item: %v\", err)\n } else {\n \tlog.Infof(ctx, \"the lyric is %q\", item.Value)\n }\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/go111/memcache).\n- Refer to the [Memcache API Reference](/appengine/docs/legacy/standard/go111/memcache/reference)."]]