

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 결과 캐시 사용을 위한 Gremlin 쿼리 힌트
<a name="gremlin-query-hints-results-cache"></a>

[쿼리 결과 캐시](gremlin-results-cache.md)가 활성화된 경우 다음 쿼리 힌트를 사용할 수 있습니다.

## Gremlin `enableResultCache` 쿼리 힌트
<a name="gremlin-query-hints-results-cache-enableResultCache"></a>

값이 `true`인 `enableResultCache` 쿼리 힌트를 사용하면 쿼리 결과가 이미 캐싱된 경우 캐시에서 쿼리 결과가 반환됩니다. 그렇지 않은 경우 새 결과를 반환하고 캐시에서 지워질 때까지 캐싱합니다. 예제:

```
g.with('Neptune#enableResultCache', true)
 .V().has('genre','drama').in('likes')
```

나중에 정확히 동일한 쿼리를 다시 실행하여 캐싱된 결과에 액세스할 수 있습니다.

이 쿼리 힌트의 값이 `false`이거나 값이 없으면 쿼리 결과가 캐싱되지 않습니다. 하지만 이 값을 `false`로 설정해도 기존의 캐싱된 결과는 지워지지 않습니다. 캐싱된 결과를 지우려면 `invalidateResultCache` 또는 `invalidateResultCachekey` 힌트를 사용하세요.

## Gremlin `enableResultCacheWithTTL` 쿼리 힌트
<a name="gremlin-query-hints-results-cache-enableResultCacheWithTTL"></a>

`enableResultCacheWithTTL` 쿼리 힌트는 캐시에 이미 있는 결과의 TTL에는 영향을 주지 않고 캐싱된 결과가 있는 경우 이를 반환합니다. 현재 캐싱된 결과가 없는 경우 쿼리는 새 결과를 반환하고 `enableResultCacheWithTTL` 쿼리 힌트로 지정된 Time to Live(TTL) 동안 해당 결과를 캐싱합니다. Time to Live는 초 단위로 지정됩니다. 예를 들어, 다음 쿼리는 Time to Live 값을 60초로 지정합니다.

```
g.with('Neptune#enableResultCacheWithTTL', 60)
 .V().has('genre','drama').in('likes')
```

60초의 Time to Live 시간이 끝나기 전에 동일한 쿼리(여기에서는 `g.V().has('genre','drama').in('likes')`)를 `enableResultCache` 또는 `enableResultCacheWithTTL` 쿼리 힌트와 함께 사용하여 캐싱된 결과에 액세스할 수 있습니다.

**참고**  
`enableResultCacheWithTTL`로 지정된 Time to Live 값은 이미 캐싱된 결과에는 영향을 주지 않습니다.  
`enableResultCache`를 사용하여 결과를 이전에 캐싱한 경우, 캐시를 먼저 명시적으로 지워야 `enableResultCacheWithTTL`이 새 결과를 생성하고 지정한 TTL 동안 캐싱합니다.
`enableResultCachewithTTL`를 사용하여 결과를 이전에 캐싱한 경우, 이전 TTL이 먼저 만료되어야 `enableResultCacheWithTTL`이 새 결과를 생성하고 지정한 TTL 동안 캐싱합니다.

Time to Live가 지나면 쿼리의 캐싱된 결과가 지워지고 동일한 쿼리의 후속 인스턴스가 새 결과를 반환합니다. `enableResultCacheWithTTL`가 후속 쿼리에 첨부되면 지정된 TTL을 사용하여 새 결과가 캐싱됩니다.

## Gremlin `invalidateResultCacheKey` 쿼리 힌트
<a name="gremlin-query-hints-results-cache-invalidateResultCacheKey"></a>

`invalidateResultCacheKey` 쿼리 힌트는 `true` 또는 `false` 값을 취할 수 있습니다. `true` 값을 사용하면 `invalidateResultCacheKey`가 연결된 쿼리에 대해 캐싱된 결과가 지워집니다 예를 들어, 다음 예제에서는 쿼리 키 `g.V().has('genre','drama').in('likes')`에 대해 캐싱된 결과가 지워집니다.

```
g.with('Neptune#invalidateResultCacheKey', true)
 .V().has('genre','drama').in('likes')
```

위 예제 쿼리에서는 새 결과가 캐싱되지 않습니다. 기존 캐싱된 결과를 지운 후 새 결과를 캐싱하려는 경우 동일한 쿼리에 `enableResultCache` 또는 `enableResultCacheWithTTL`를 포함할 수 있습니다.

```
g.with('Neptune#enableResultCache', true)
 .with('Neptune#invalidateResultCacheKey', true)
 .V().has('genre','drama').in('likes')
```

## Gremlin `invalidateResultCache` 쿼리 힌트
<a name="gremlin-query-hints-results-cache-invalidateResultCache"></a>

`invalidateResultCache` 쿼리 힌트는 `true` 또는 `false` 값을 취할 수 있습니다. `true` 값을 지정하면 결과 캐시의 모든 결과가 지워집니다. 예제:

```
g.with('Neptune#invalidateResultCache', true)
 .V().has('genre','drama').in('likes')
```

위 예제 쿼리에서는 결과가 캐싱되지 않습니다. 기존 캐시를 완전히 지운 후 새 결과를 캐싱하려는 경우 동일한 쿼리에 `enableResultCache` 또는 `enableResultCacheWithTTL`를 포함할 수 있습니다.

```
g.with('Neptune#enableResultCache', true)
 .with('Neptune#invalidateResultCache', true)
 .V().has('genre','drama').in('likes')
```

## Gremlin `numResultsCached` 쿼리 힌트
<a name="gremlin-query-hints-results-cache-numResultsCached"></a>

`numResultsCached` 쿼리 힌트는 `iterate()`를 포함하는 쿼리에만 사용할 수 있으며, 힌트가 첨부된 쿼리에 대해 캐싱할 최대 결과 수를 지정합니다. `numResultsCached`가 존재할 때 캐싱된 결과는 반환되지 않고 캐싱되기만 한다는 점에 유의하세요.

예를 들어, 다음 쿼리는 결과를 최대 100개까지 캐싱하되 캐싱된 결과는 반환되지 않도록 지정합니다.

```
g.with('Neptune#enableResultCache', true)
 .with('Neptune#numResultsCached', 100)
 .V().has('genre','drama').in('likes').iterate()
```

그런 다음 아래와 같은 쿼리를 사용하여 캐싱된 결과 범위(여기서는 처음 10개)를 검색할 수 있습니다.

```
g.with('Neptune#enableResultCache', true)
 .with('Neptune#numResultsCached', 100)
 .V().has('genre','drama').in('likes').range(0, 10)
```

## Gremlin `noCacheExceptions` 쿼리 힌트
<a name="gremlin-query-hints-results-cache-noCacheExceptions"></a>

`noCacheExceptions` 쿼리 힌트는 `true` 또는 `false` 값을 취할 수 있습니다. `true` 값이 지정되면 결과 캐시와 관련된 모든 예외가 억제됩니다. 예제:

```
g.with('Neptune#enableResultCache', true)
 .with('Neptune#noCacheExceptions', true)
 .V().has('genre','drama').in('likes')
```

특히 이 경우 쿼리 결과가 너무 커서 결과 캐시에 담을 수 없는 상황에서 발생하는 `QueryLimitExceededException`이 표시되지 않습니다.