blob: b1639bd88b8694c5dde531650f69140243d1be00 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/containers/flat_map.h"
#include "base/containers/mru_cache.h"
#include "components/ntp_snippets/contextual/contextual_suggestions_result.h"
#include "url/gurl.h"
namespace contextual_suggestions {
// Wrapper for an LRU cache of ContextualSuggestionResult objects, keyed by
// context URL.
class ContextualSuggestionsCache {
explicit ContextualSuggestionsCache(size_t capacity);
// Attempts to find a result for |url| in this cache, returning true and
// putting the result into |result| if successful.
bool GetSuggestionsResult(const GURL& url,
ContextualSuggestionsResult* result);
// Adds |result| to this cache for the key |url|, overwriting any previous
// value associated with |url| and potentially evicting the oldest item in the
// cache.
void AddSuggestionsResult(const GURL& url,
ContextualSuggestionsResult result);
// Removes all items from the cache.
void Clear();
// Returns all suggestion results for debugging purposes.
base::flat_map<GURL, ContextualSuggestionsResult>
base::MRUCache<GURL, ContextualSuggestionsResult> cache_;
} // namespace contextual_suggestions