Topical Result Caching in Web Search Engines

Caching search results is employed in information retrieval systems to expedite query processing and reduce back-end server workload. Motivated by the observation that queries belonging to different topics have different temporal-locality patterns, we investigate a novel caching model called STD (Static-Topic-Dynamic cache). It improves traditional SDC (Static-Dynamic Cache) that stores in a static cache the results of popular queries and manages the dynamic cache with a replacement policy for intercepting the temporal variations in the query stream. Our proposed caching scheme includes another layer for topic-based caching, where the entries are allocated to different topics (e.g., weather, education). The results of queries characterized by a topic are kept in the fraction of the cache dedicated to it. This permits to adapt the cache-space utilization to the temporal locality of the various topics and reduces cache misses due to those queries that are neither sufficiently popular to be in the static portion nor requested within short-time intervals to be in the dynamic portion. We simulate different configurations for STD using two real-world query streams. Experiments demonstrate that our approach outperforms SDC with an increase up to 3% in terms of hit rates, and up to 36% of gap reduction w.r.t. SDC from the theoretical optimal caching algorithm.


Introduction
Caching is a fundamental architectural optimization strategy [14], and query-result caching is critical for Web search efficiency. Query-result caching, as its name implies, stores the results of some selected user queries in a fast-access memory (cache) for future reuse. When a query is requested and we have a hit in the cache, the cached results are directly returned to the user without reprocessing the request. Result caching improves the main efficiency-performance metrics of search engines, namely, latency and throughput. Indeed, serving the cached results decreases the latency perceived by the user issuing the query as well as avoids the usage of computational resources with a consequent improvement of the search engine throughput.
Another advantage of caching query results is the reduction of energy consumption as cached queries do not need to be reprocessed by the back-end servers. Although other energy-efficiency optimization schemes exist [15,16,30,44], these approaches are complementary to result caching and not a contradictory alternative. Given desired and imposed "Green Policy" restrictions and the significant economic benefits due to the energy conservation, the interest of the search industry in energy saving is high. Energy wise, the cost of a cached query is typically assumed to be nil, while a search of a query costs proportionally to its processing time in combination with the electricity price at the time of processing [40].
The main challenge in query-result caching is the identification of those queries whose results should be cached. However, via query log mining, researchers observed high temporal locality in the query stream, enabling accurate search-engine side caching of popular query results, i.e., results of queries frequently requested by different users [39,46].
The query-result cache can be static or dynamic. A static cache is periodically populated in an offline manner, with the results of past, most-popular queries. Query popularity is estimated observing previously submitted queries (e.g., previous day or week) in Web search logs; a simplifying, but not always correct, core assumption is that queries popular in the past remain popular in the future. A dynamic cache, as the name suggests, is dynamically updated; when the cache is full, an eviction/replacement policy is applied to decide which cache element must be removed to make space for the new one. The most common replacement policy for dynamic caches is the Least Recently Used (LRU) strategy: every time a query is submitted, the cache is updated, keeping track of what query was used and when; if necessary, the cache entry used least recently is evicted to vacate space for the new entry. The LRU strategy is effective without global knowledge and captures the "bursty" behavior of the queries by keeping recent queries in the cache and replacing those queries that are not requested for a long period of time.
Static and dynamic caches can be combined together. Fagni et al. [20] proposed a Static-Dynamic Cache (SDC) where the cache space is divided into two portions. The static portion stores results of the most popular queries, such as "microsoft," "youtube," or "facebook." The dynamic portion maintains currency by applying the LRU strategy. This hybrid approach has proved successful in improving the performance of query-result caching with respect to both static and dynamic caching solutions in isolation. Despite its good performance, SDC suffers from some issues. Static caching captures highly frequent queries, while LRU caching captures bursts of recently submitted queries. That is, static caching captures past queries that are popular over a relatively large time span (e.g., days or weeks) while LRU caching might fail to capture such long-term temporal locality, but does capture short-term popularity. However, a query might not be sufficiently globally popular to be cached in the static cache and not be requested so frequently to be kept in the dynamic cache, but it might become relatively popular in a specific time interval. For example, a query on a specific topic, such as weather forecast, is typically submitted in the early morning hours or at the end of a work day, but relatively seldom in the remaining hours of a day.
We design a cache for query results that can adapt the cache-space utilization to the popularity of the various topics represented in the query stream. The intuition behind our approach is that queries can be grouped based on broad topics (e.g., the queries "forecast" and "storm" belong to the topic weather, while queries "faculty" and "graduate" to the topic education), and queries belonging to different topics might have different temporal-locality patterns. We assume that the topic popularity is represented by the number of distinct queries belonging to the topic; to capture the specific locality patterns of each topic we split the cache entries among the different topics proportional to their popularity. This provides queries belonging to frequently requested topics greater retention probability in the LRU cache.
As an illustrative example, consider a cache with size 2 and the query stream abcadeafg, where query a is about a specific topic. A classical LRU strategy will get a 0% hit rate (all queries will cause a miss). Instead, using 1 entry for the topic cache and 1 entry for the LRU cache we will get a 22.2% hit rate (the first occurrence of a causes a miss, the other two occurrences will cause two hits in the topic cache).
The topic cache can be combined with a static cache in different configurations. We propose to improve the SDC approach by adding yet an additional cache space partition that stores results of queries based on their topics. We call our approach Static-Topic-Dynamic cache (STD) and in Fig 1 is shown an example of it. To detect the query topics and incorporate them in the caching strategy we rely on the standard topic modeling approach called Latent Dirichlet Allocation (LDA) [11]. LDA gets as input a document collection and returns lists of keywords representing the topics discussed in the collection. Each document in our setting consists of the query keywords and the textual content of their clicked results. Given the topics, the queries can be classified into topical categories, and we estimate the topic popularity by observing the number of distinct queries belonging to that topic.
For our experiments, we use real-world query logs from AOL and Microsoft search engines, and we observe that modifying the caching strategy to include the topic partition increases the cache hit rate by greater than 3 percent with a consequent improvement of the query processing performance. This increase greatly reduces the gap w.r.t. Bélády's optimal caching policy [10], measured as the difference between the hit rate of Bélády's policy and the hit rate of SDC/STD policies. While the SDC gap is ∼10%, the STD gap is ∼6%, with a relative improvement of more than 35% when no cache admission policy is applied. This result is very good for query-result caching, considering that SDC is the state-of-the-art and other attempts to enhance it resulted in small improvements [27].
Compared to a traditional SDC cache, we observe that our caching technique captures moderately popular queries not captured by the static cache; additionally we capture requests repeated within a large time interval that are likewise not captured by the dynamic cache. Some examples of queries that cause a miss in SDC but not in STD are first bank, texas state bank, first national, renasant bank for the topic banking, education world, everyday math, french-english dictionary for the topic education and florida department of health, arthritis foundation, st vincents hospital, st marys hospital for the topic health, just to mention a few of them.
The paper is structured as follows: Section 2 provides background information and discusses the related work in Web search engine caching, while Section 3 introduces our STD cache model and different configurations of the topic-based cache, followed by how the topics are distilled. Then, Section 4 describes and analyzes the query logs and document collections used for the assessment of the performance of our STD cache(s). Section 5 details the experimental settings and reports on the results of our comprehensive evaluation. Finally, we conclude our investigation in Section 6.

Related Work
As background, we overview related efforts investigating query log mining, caching solutions in Web search engines, and query topic distillation.
Query Log Mining. Information extracted from query logs (e.g., search keywords, users' IDs, query timestamps, and clicked results) allows us to understand the behavior of users interacting with the search engine and, consequently, to enhance the effectiveness and efficiency of the retrieval systems. This desire for user behavioral understanding motivated researchers to investigate the mining of Web search logs in many different directions [42].
Raghavan and Sever [37] performed a first study on how to use past knowledge to improve the effectiveness of information retrieval. They proposed to improve the result retrieval for queries similar to a query base which is obtained from past optimal queries mined from query logs. Another approach exploits information extracted from query logs (e.g., query frequencies and distribution) for enhancing the performance of search engines, such as designing new caching strategies [20,28] and assessing the performance of caching techniques [33]. Other researchers analyzed query logs observing high correlations among query terms [41] and common searching behavior among Web users (e.g., short queries) [24,43]. A further analysis focusing on the temporal locality of queries was presented by Beitzel et al. [8]. The authors analyzed one week of data, grouping queries per hours and per topic to see how their popularity changes during the day. They observed that the query repetition rate is constant during the day, even though each popular query does not appear frequently in every hour. This result confirms the intuition that queries grouped by topic show some specific temporal localities in the stream.
Caching in Web Search Engines. Modern search engines are large-scale distributed systems where the inverted index is partitioned and stored among multiple back-end machines, each one running a search node. In addition, there is a front-end machine hosting the broker for scheduling the queries among the different search nodes [7]. When the query is submitted, the front-end machine sends its keywords to the different back-end machines, each one responsible of searching a given portion of the index. Then, it collects the results to recreate the Search Engine Result Page (SERP).
In modern search engines, query processing represents one of the major performance bottlenecks, so caching can help to speed up the search engine performance as well as to reduce the latency perceived by the users. Caching can be applied at different granularity including query results [28], posting lists of query terms [39], and posting list intersections [31]. Saraiva et al. [39] proposed a two-level architecture where the front-end machine caches the results of popular queries, while the back-end machines have a cache for the posting lists of most frequently requested terms. This architecture gets the benefits from both types of caching. Indeed, caching query results is faster since future requests of a query whose results are cached can be served immediately, without further processing, but it has a lower hit rate since a hit in cache occurs only with exact-matching queries. On the other hand, caching posting lists entails a better hit rate since the term overlap is greater, but the query needs to be processed by the back-end servers and the only saving is in the number of I/O operations over the disk storing the inverted index. Two-level caching was also studied by Baeza-Yates et al. [6] in the static setting and by Altingovde et al. [2] for dynamic setting.
Three-level architectures store in the additional level of the cache the precomputed intersections of posting lists [31,45,47]; this improves the processing of more complex queries such as AND or phrase queries. Ozcan et al. [34] presented an even more sophisticated cache consisting of five levels for storing query results, precomputed scores, posting lists, precomputed intersections of posting lists, and documents. The caching approach is based on a greedy heuristic which allows to select the best item to cache. Each level of the cache has a priority queue, and the items are ordered in the queue according to their gains reflecting the frequency of the item's past accesses as well as its processing cost and storage overhead. We focus on a cache employed at the level of the front-end machine to store the results of most frequently requested queries. Our cache for query results can be used in combination with these multi-level cache architectures, as well. Improving the hit rate of the query-result cache is in fact beneficial for the lower layers of the caching system that provide an efficient processing of queries resulting in misses in the top-level cache.
The query-result cache enhances the responsiveness of the search engine and saves resources. Depending on the space available, the cache can keep the entire HTML page (SERP cache) [20,28,33] or the URLs and/or snippets used for reconstructing it (DocID cache) [39]. Caching the whole page of results requires more space and the same page cannot be used for different but similar queries; however, it is faster because when the query is requested, its cached SERP can be returned promptly. On the other hand, the DocID cache allows to use the cache space in a more efficient way, but it is slower because even when we have a cache hit, some time would be needed to reconstruct the SERP. In [2], the authors proposed two levels of caching: first level for the SERPs and the second one for result documents of SERPs evicted from the first level cache. This allows to reconstruct the pages missing from the first level cache on the front-end server without processing the query on the back-end machines.
The query-result cache can be managed in a static or dynamic way. A static cache is periodically (every day or week) populated with the results of frequent queries. Indeed, several authors observed that query frequency follows an inverse power law, which means that most of the queries are submitted a few times (e.g., they are long, with typos, or very rare), but a small portion of queries are requested several times and shared by different users [20,28,46]. This justifies the use of a server-side static cache storing results of these queries. The cache is updated with the results of most popular queries observed in the previous period and for re-freshing the results. A dynamic cache changes the content of entries according to the query stream, and it applies a replacement policy for deciding which element must be evicted when the cache is full. This policy tries to minimize the number of misses, and a popular one is Least Recently Used (LRU) which evicts the item not requested for the longer period of time. Markatos [33] compared the hit rates achieved by LRU and its variations (e.g., Segmented LRU and LFU) over a query stream from the Excite query log. He observed that the LRU policy (and its variations) is very effective in query-result caching as it captures the temporal changes in the stream of requests. Although his work did not propose any novel caching algorithm, it showed the potentiality of caching in Web search. Static and dynamic caches can be combined to improve the hit rate. Fagni et al. in [20] presented Static-Dynamic Cache (SDC), consisting of a static portion for storing the results of most frequent queries and a dynamic portion for which an LRU-like approach is applied. Combined or not with prefetching strategies, SDC outperforms purely static or dynamic caching policies. We present a further improvement of SDC by adding another layer which is made of several topic-dependent LRU caches.
To improve cache performance, the system can apply an admission policy which accepts to the cache only those queries with a high re-submission probability. The idea behind these policies is that caching search results of queries that are not requested anymore or are requested after a long time (and generally after their eviction from the cache) should be avoided. Indeed, these queries (also called "polluting" queries [5]) would only waste space in the cache, so it would be better to just ignore them and give more chance to the results of other queries to be kept in the dynamic portion of the cache (e.g., the LRU queue). These policies mostly rely on features extracted from the queries or from usage information [5,21,27]. Baeza-Yates et al.
proposed an admission policy for restricting unfrequent and too long queries from entering the cache [5]. In [27], Kucukyilmaz et al. proposed a machine learning approach for predicting the next queries to cache. Their approach is based on features extracted from the query, index, term frequency, query frequency, and user session. This policy on top of SDC yields to a small improvement of the hit rate compared to the one achieved with our novel caching model. Recent works employed machine learning to predict queries not worthy to be cached [35] or to adjust the time-to-live values of queries [1]. Alternatively, the policy can favor queries that are more costly to process [3]. Other works focus on predicting stale queries [25] and use the information extracted from both queries and session features to increase the hit rate of the cache. We do not investigate novel admission policies; rather we use them in coordination with our caching model as they allow to enhance the input stream of queries. We followed [5] and used the stateful and stateless features of queries for implementing the admission policy. The former is given by statistical information computed over the past stream (e.g., the number of times the query was submitted in the past). The latter is based on the query characteristics (e.g., the length of the query). The idea is to avoid the caching of infrequently requested queries; long queries are typically rare and are unlikely to be resubmitted. Moreover, we computed an upper bound of the best hit ratio that can be achieved using an admission policy with a cache of a given size. For this reason we used the Bélády's optimal caching policy [10] that assumes to know the future and evicts the results of the query not requested for the longest time (representing the best replacement policy) and an oracle which knows the future and does not admit in the cache the singleton queries (representing the best admission policy).
Orthogonal research works focus on caching single results (e.g., URLs and snippets) that are used for reconstructing the final page of results of queries (SERP). Cambazoglu et al. [13] present techniques for computing result pages of unseen queries starting from the cached results of previously requested query. Ceccarelli et al. investigate the problem of caching query-based snippets [17]. In [4], the stochastic query covering approach is presented for selecting the set of documents to store in the cache. These documents serve many queries and can be used for fast retrieval as well as for approximating the results of a query when the connection between the front-end server with the back-end machines is too slow or unavailable. We do not aim at improving document caching as our strategy for query-result caching is orthogonal to it and can be employed together with a document cache in a two-level fashion architecture as in [2]. So, the first level caches the SERPs of queries, while the second level caches the documents used for reconstructing the SERPs. When one of the SERP is evicted from the first level cache, the system may decide to cache its documents in the second level cache, so that queries evicted from the first level cache have a second chance to be served by cached documents stored in the second level cache.
Another line of research focuses on index tiering [26] as well as on document replication [19]; these techniques can be employed in synergy with server-side caching with the purpose of improving the performance of distributed search engines.
Query-Topic Distillation. Two challenging problems in query log mining are query classification and querytopic distillation. Flat and hierarchical taxonomies were proposed for classifying the user queries, even though these taxonomies are limited to some specific domains and provide a broad categorization [12,43].
Query-topic distillation/detection can improve quality of the Web search [9]. It allows to distill the multiple possible topics behind an ambiguous/broad query which is beneficial for better understanding the query intention and improving the automatic reformulation of queries [23]. Nevertheless, query-topic detection is not easy due to the shortness and lack of context of queries. One possible approach for understanding the topic of a query is enriching its search keywords with the content (from snippet or page) of its top results [23]. Another solution consists of using the content of only the clicked results. As explained in Sec. 3, we opted for this second solution since the user click is a strong indicator of the relevance of the document to the query. Once the search queries are enriched with page content, the resulting document collection can be used to discover the topics. Text clustering techniques or topic modeling approaches can be applied. Topic models have been used for several years as they allow to discover the topics discussed in large document collections [11,29,38]. We opt to use a topic-model approach (e.g., LDA [11]) as it is completely unsupervised and domain independent, plus it leverages the word co-occurrences, providing better results compared to a basic text clustering approach [32].

Methodology
We propose a new query-result caching strategy based on user search topics. We first describe our caching architecture, including possible implementation configurations, and continue by discussing our query topic extraction approach. We assume that the cache stores the SERPs of the queries; onward we use query results or just results to refer to the content of a cache entry.

Topic-based Caching
Given the total number N of cache entries available for storing the results of past queries, we propose a Static-Topic-Dynamic (STD) cache which includes the following components: • a static cache S of size |S| = f s ·N entries, used for caching the results of the most frequently requested queries. The static cache S is updated periodically with the fresh results of the top frequent |S| queries submitted in the previous time frame (e.g., the previous week or month). This static cache is expected to serve very popular queries such as navigational ones (e.g., "google" and "facebook"); • a topic cache T of size |T | = f t · N entries, which is in turn partitioned in k topic-based sections T .τ , with τ ∈ {t 1 , t 2 , . . . , t k }, where k is the number of distinct topics. Each section T .τ is considered as an independent cache, managed with some caching policy (e.g., LRU or SDC), and aimed at capturing the specific temporal locality of the queries belonging to a given topic, i.e., queries more frequent in specific time intervals or with periodic "burstiness" (e.g., queries on weather forecasting, typically issued in the morning, or queries on sport events, typically issued in the weekend); • a dynamic cache D of size |D| = f d · N . The dynamic cache D is managed using some replacement policy, such as LRU. It is expected to store the results of "bursty" queries (i.e., queries requested frequently for a short period of time) that are not captured by neither S nor T as they are not sufficiently popular or are unassigned to any of the k topics. Queries cannot be assigned to a topic for two reasons: (i) the query was never seen before, hence the topic classifier fails to detect its topics, or (ii) even though it was already submitted in the past, no topic was assigned to it due to a very low classification confidence (see Sec. 3.3).
The parameters f s , f t , and f d denote the fractions of entries N devoted to the static, topic, and dynamic caches, respectively, so that f s + f t + f d = 1. Note that, if f t = 0, our STD cache becomes the classical SDC cache. The number of entries in each section T .τ of the topic cache can be fixed, i.e., |T .τ | = |T |/k, for every τ ∈ {t 1 , . . . , t k }, or chosen on the basis of the popularity of the associated topic (observed in a past query stream). In the latter case, we model the topic popularity as the number of distinct queries in the topic, since estimating this number allows us to assign to the topic a number of entries proportional to its requested queries. This entails a more efficient utilization of the cache space since queries belonging to a popular topic have greater chances to be retained in the cache as their topic receives more entries as compared to other queries belonging to unpopular topics.
In Fig. 2 we show an example of how the proposed cache can be employed in a search engine system. The management of the STD cache is reported in Alg. 1. When a query with its topic τ ∈ {t 1 , . . . , t k } arrives, the cache manager first checks if the query is in the static cache S. If so, we have a hit; otherwise, if the query has a topic handled by the cache, the manager checks the topic-specific section of the topic cache T .τ , updating the topic cache with its specific replacement policy, if necessary, and producing a hit or a miss if the query was cached or not. If the query was not assigned to any topic, the dynamic cache D is responsible for managing the query and producing a hit or a miss. We note that the pseudo-code does not detail the retrieval of the query results from the cache or its processing on the inverted index of the search engine in case of hit or miss, respectively.  Algorithm 1: The STD cache management process. Input : A query q and its topic τ Output: Hit or miss and updated STD cache Note that the cache misses incur different costs since some queries are more expensive to process than others (in term of time and resources). For our research purpose of comparing different caching architectures, however, we simplify the performance analysis and focus on the hit rate, considering all the misses with the same cost. In other efforts that focus on determining which element must be evicted from the dynamic cache or admitted to the static cache, the cost of the misses is taken into account [3,21,35]. Anyway, these strategies, based on how costly is the computation of query results, can be used in synergy with our caching architecture to improve the overall performance.

STD Cache Configurations
Our proposed STD cache model can be implemented in different ways, depending on several parameters such as the values of f s , f t and f d , the number of entries assigned to each topic in the topic cache, the replacement policy adopted, and so on. In the following, we illustrate some of these implementations (see Fig. 3), which will be part of our experimental evaluation (see Sec. 5).
• STD with topic cache managed by LRU with fixed size (STD f LRU ). This cache includes the static, topic, and dynamic caches discussed above. The topic cache entries are divided equally among the different topics (i.e., without taking into account the topic popularity), and each topic cache section is managed according to the LRU replacement policy.
• STD with topic cache managed by LRU with variable size (STD v LRU ). This cache is similar to the previous one with the difference that each topic has a number of entries proportional to its popularity. We quantified this topic popularity as the number of distinct queries that belong to the topic in the training set of the query log.
• STD with topic cache managed by SDC with variable entry size (STD v SDC ). This cache is similar to the STD v LRU cache, but now the topic cache is managed by SDC instead of LRU. Each topic gets a given number of entries proportional to its topic popularity, and all topic cache sections are split in a static and dynamic cache. The fraction of entries allocated to the static portion of these caches is a constant fraction of the topic cache entries and denoted with f s t . The remaining entries, allocated for the topic, are managed by LRU.
• Topic-only cache managed by SDC with variable entry size (T v SDC ). This is an alternative version of the previous implementation since the queries with no topic are managed as queries belonging to an additional topic k + 1. This means that instead of having a predefined size for static and dynamic caches, the number of entries would depend on the number of queries without a topic.

Modeling Queries as Topics
Query topic categorization of user queries is well addressed within Web companies to increase effectiveness, efficiency, and revenue potential in general-purpose Web search engines [9]. Unfortunately, we cannot rely on the query topic characterization provided by the search engine industry since this information is missing from the query logs we use. Thus, to distill the topics of the queries in our query logs, we rely on LDA topic modeling.
Latent Dirichlet Allocation (LDA) [11]. LDA is an unsupervised approach not requiring any prior knowledge of the domain for discovering the latent topics. Given a collection of documents and the number k of topics, it returns k lists of keywords, each representing a latent topic. Let θ d be the per-document topic distribution, which is assumed to be drawn from a Dirichlet distribution with hyper-parameter α. The documents are a mixture of topics, and the multinomial random variable z d,n of a topic to appear in position n of document d is conditioned on θ d . Words appearing in a document are selected according to another multinomial distribution with hyper-parameter β, conditioned on the chosen topic. In this way, each word has a probability that depends on its likelihood to appear in the document relevant to the topic. In summary, LDA can be seen as a generative process where documents are generated sequentially as reported in Alg. 2. By inverting the generative process, it is possible to infer the topics from the words appearing in the documents. So, given a document d, we have to compute the posterior distribution of the hidden variables z d and θ d as follows: where the vector w d represents the words observed in d, while the vector z d represents the positions of words in d. Both vectors have the same size, equal to the length of d. Statistical inference techniques, such as Gibbs sampling [22], are employed to learn the underlying topic distribution θ d of each document.
Finding Latent Topics from Query-Document Pairs. Given a training query log, we aim at learning a query topic classifier based on LDA. Since queries are short and lack context, it is difficult to train the model accurately. To circumvent this problem, we enrich the queries with the content of their clicked pages whose URLs are available in the training query log. We thus create a collection of query-document samples made of queries plus the text of their clicked results gathered from the Web. In case, for a given query, the user did not click any results, or the clicked URL was not available any longer, we remove the corresponding query from the set. Given a query-document pair, we use this content as a proxy of the query, and train LDA to learn the topics discussed in the collection of query-document pairs. The trained LDA classifier returns a distribution of topics for each query-document pair. Since we assume that a query can be assigned to only one topic, we always choose, for the pair, the topic with the highest probability. In our experiments, we use different query logs w.r.t. the training one, and we assume the LDA classifier is able to classify only queries already seen in the training query log, since for new queries we will lack the content of clicked pages.
Query Topic Assignment. Once we know the topics of the proxy query-documents, we must assign a single topic to each query. Since the same query might appear in different query-document pairs, possibly assigned to different topics, we must decide which one of these topics should be associated with the query. To this end, we adopted a simple voting scheme that assigns to each query the topic of the query-document that got more clicks by the users. In doing so, we leverage the strong signal coming from clicks about the relevance of a document and its topic to the information need expressed by the query. Also, it allows us to estimate the most popular topic that can be assigned to ambiguous queries (i.e., queries with more than one meaning that have more possible topics). Estimating Topic Popularity. In some of the implementations of our topic cache (i.e., STD v LRU , STD v SDC , T v SDC ), we assign to each topic an amount of cache entries proportional to the topic popularity. Similarly to the static cache, where past popular queries are assumed popular in the future, we assume that popular topics observed in the past remain popular in the future; so they get more entries in the topic cache T .
We quantified this topic popularity as the number of distinct queries that belong to the topic q τ . Note that this statistic is computed over the training period. More in detail, let |T | be the size of the topic cache, q be the number of distinct queries in the training set, each topic τ will get a number of entries |T .τ | equal to where the symbol x is the nearest integer to x. For example, suppose we have a topic cache with size |T | = 5 and 9 distinct queries observed in the training: 6 for the topic weather and 3 for education, we will have |T .weather| = 3.33 = 3 and |T .education| = 1.66 = 2.

Dataset Description
Query logs. For our experiments, we used two real-world query logs, namely, the AOL and MSN query logs. The AOL query log [36] consists of about 36M of query records, submitted by 650K users over a period of three months (from March to May 2006). Each record in the dataset is made of the user ID, the query keyword(s), the timestamp, the rank and the URL of the domain of the clicked result. The last two fields represent a click-through event, and they are present only if the user clicked on a search result. About 19.4M records have a domain URL, and the number of distinct URLs is 1.6M . Notice that, when a user clicked on more than one result in the same search session, there are repeated records for that query (one for each clicked result). Hence, for our experiments, we recreated the query stream by removing the duplicated records representing multiple clicks for the same query, and we kept only the "first query" of the sequence. The final query stream, used for the simulation of the cache, consists of 20M queries.
The MSN query log [18] consists of about 14.9M records storing the timestamp, the search keyword(s), the query id, the session id, and the result count. About 8.8M records have a clicked URL for a total of 3.4M distinct URLs.
For both datasets, we preprocessed the queries by removing special characters and converting them to lowercase. After the preprocessing, the number of distinct queries is 9.3M and 6.2M for AOL and MSN, respectively. The distribution of the query popularity follows a power law in both query logs as shown in Fig. 4. We plot the distribution using a log-log scale; the queries are ordered along the x-axis by popularity, while the number of occurrences of the query (i.e., query frequency) is shown on the y-axis. We partitioned both query logs into two portions, one for training purposes (e.g., cache initialization) and one for testing the performance of the cache. We sorted the query logs by time and split them into two fractions: X for the training set and 100 − X for the test set with X = 30%, 50%, and 70%. We present the results for the 70%-30% split for caching without admission policies, but we observed similar results for the other training-test splits. In this case, the training (resp. test) set contains 6.7M (resp. 3.2M ) unique queries for AOL and 4.5M (resp. 2.1M ) unique queries for MSN. We also tried different splitting of the datasets, such as weekly splits, but the average results were not much different from the ones reported in the next section. Document Collections. Given the URLs from both query logs, we collected the associated pages from the Web, and gathered 1M documents for AOL and 2.1M documents for MSN. Then, we extracted and preprocessed the text (e.g., stop-word removal, lemmatization, and stemming). We removed overly short and long documents (less than 5 and more than 100K words). Lastly, we enriched the documents with the corresponding query keywords.

LDA Topics.
To train the LDA model we subsampled the documents from the training period and used 500K documents from AOL and 350K documents from MSN query log. Notice that this training is only used for learning the topics discussed in the collection (e.g., sport, politics, weather). After the topic detection, given a query and its clicked result we use LDA to predict the topic of the query.
We removed the very frequent and rare words from the dictionary, and we set the number k of topics to discover to 500, estimated empirically. The approach is probabilistic, hence the topic detection can change with different collections and different number of topics. We tried other configurations, changing the subsets of documents in the training set and using different values of k (e.g., 50, 100, and 500); we observed that the impact on the caching performance was negligible. Some of the topic keywords, extracted from the AOL dataset, are shown in Table 1.
In Fig. 5, we report the distribution of topics extracted from both datasets. It is worth noting that the topic portion of STD cache exploits the subset of queries in the test set stream having a known topic. These queries are necessarily among those already encountered in the training set stream and successfully classified. The test queries that were not assigned to a topic compete instead for the use of the static and dynamic portions of the STD cache. The percentage of queries in the test set with a topic is 65% for AOL and 58% for the MSN query log.

Experiments
We ran our experiments using the AOL and MSN query logs described in Sec. 4. For the caching simulations, we considered the scenario of storing the query results in the cache (e.g., the first SERP). We took as input the stream of queries. If the query is found in the cache we have a cache hit; otherwise, there is a cache miss. In case of miss, if the query is not filtered out by the admission policy implemented (if any) and the dynamic portion of the cache is full, the eviction policy is applied to vacate space for the query results.
For our experiments, we set the cache size N to different values: 64K, 128K, 256K, 512K, and 1024K. Given the small size of our query logs and the training period needed for learning the topics and the cache initialization, we simulated for our experiments small-and medium-sized caches. In reality, the caches employed by modern search engines are much bigger, but they are always too small compared to the number of queries submitted by the users.
The data in the training set are used for three purposes: (1) learning the frequency of the queries and loading popular queries in the static cache(s), (2) training the LDA topic classifier from the queries (and clicked documents) and estimating their popularity for balancing the entries of the topic cache(s), and (3) warming up the LRU cache(s). We assess the cache performance in terms of hit rate, namely the number of cache hits in the test set divided by the number of queries in the test set.
For our experiments, we considered the following cache organizations: • SDC: we used as baseline the traditional static and dynamic cache, where the dynamic portion is managed by LRU. This approach is considered the state-of-the-art technique for query-result caching as also confirmed by recent works on caching that used SDC as a principal baseline (e.g., [27]).
• STD f LRU : the STD cache where the topic cache is managed by LRU and all topics receive the same amount of entries.
• STD v LRU : the STD cache where the topic cache is managed by LRU and the topics receive an amount of entries which is proportional to the topic popularity, as explained in Sec. 3.
• STD v SDC : the STD cache where the topic cache is managed by SDC and whose size depends on the popularity of the topic. Compared to the previous two configurations, this cache has another parameter f s t representing the static fraction of the SDC used inside the topic cache. In our tests, we include two different implementations of this configuration. In the first implementation, the static cache S stores only the frequent queries with no topic (C1) as the popular queries assigned to a topic would be stored in the static portion of the corresponding topic cache. In the second implementation (C2), the S stores all the top queries (with or without the topic). For popular queries with topic, the algorithm checks if they are already in S. If not, it stores them in the f s t fraction of entries of the corresponding SDC used in topic cache.
• T v SDC : The cache entries are divided proportionally to the topic popularity and the no-topic queries that belong to an additional topic τ = t k+1 .
For the baseline SDC cache and the proposed STD cache configurations, the static parameter f s varies from 0.0 to 1.0 with step of 0.1, while the other parameters (f t and f d ) are tuned based on the remaining size of the whole cache, e.g., N · (1 − f s ). Regarding STD v SDC , the fraction of static of the SDC caches used in the topic portion, f s t , is the same for all the topics. We also experimented with variable f s t estimates 0 100 200 300 400 500 Topics ordered by popularity per topic, but the overall experimental results are similar to those achieved with a fixed f s t , and we do not report them here.
We investigate the following research questions: RQ1. For a given cache size, is our proposed STD cache able to improve the hit rate performance metric w.r.t. SDC and, if so, adopting which configuration and optimal parameter values?
RQ2. Given the best STD competitor identified in RQ1, what is the impact of the other configuration parameters? In particular, given a static fraction f s , what is the impact of the topic and dynamic caches of STD w.r.t. the dynamic cache of SDC?
RQ3. How large are the hit rate improvements of the best STD configuration w.r.t. SDC, measured in term of the distance with the hit rate of a theoretical optimal caching strategy?
RQ4. Do the query admission policies affect the caching performance? How do these policies impact performance gains of STD over SDC?
To address RQ1, we assumed a cache with a given number of entries (e.g., N is defined by the system administrator), and we aim to discover the best cache configuration and parameters in terms of hit rate. Table 2 reports the best hit rates obtained with SDC (our baseline) and the other topic-caching strategies for different cache sizes. For each caching strategy, we report also the values of the f s , f t , f d , and f s t that achieved the best hit rates. As shown, not all parameters are used by all the cache configurations, so for those caches where the parameter is not needed we use the symbol −. For each cache size, the best hit rates are highlighted in bold. Our experiments showed that with both datasets the STD caches always perform better than SDC in terms of hit rate. In particular, the STD v SDC (C2) configuration performs always better than the others. As expected, STD f LRU performs worse than STD v LRU as it gives to each topic the same number of entries instead of allocating the topic cache entries proportionally to the topic popularity. Moreover, STD v SDC (C1) cache exhibits lower hit rates compared to STD v SDC (C2) and STD v LRU caches. Analyzing the cache misses encountered with (C1), we see that this reduction of performance is due to the fact that the static cache S of (C1) hosts only the results of no-topic queries. Some of these queries may be not very popular, hence storing them in the static fraction causes a lower hit rate in static with a reduction of the overall performance. In particular, this phenomenon is more evident when f s increases, since we are allocating more space to S and, at some point, also infrequent no-topic queries are selected just to fill in the space. Nevertheless, (C2) does not suffer from this, since it stores in S the frequent queries (with or without topic), allowing a better utilization of the static fraction of the whole cache. We could also observe that the T v SDC cache has lower performance than the other STD configurations. In most of the cases it performs close to SDC, and for small caches it does not improve the baseline. Anyway, we believe that its results allow us to better understand the benefit of using a topic cache together with static and dynamic caches. In STD f LRU , STD v LRU , and STD v SDC the amount of entries dedicated to the no-topic queries is limited by the parameter f d . Hence, there is a fair division of the cache space among the queries belonging to a topic and those that could not be classified. On the other hand, in T v SDC the no-topic queries are treated as queries belonging to an extra topic (i.e., t k+1 ), so the amount of entries is proportional to the popularity of the (k + 1)-th topic, penalizing the other k topics. Since in our data most of the queries are not classified, this leads to an unbalanced splitting of the space between the no-topic queries and the others.
We investigated the reasons why our STD cache outperforms the SDC baseline. Since the higher STD hit rate is due to less misses encountered, we analyzed the average distance of misses in the test streams (avg. miss distance). This distance is defined as the number of queries between two misses that were caused by the same query, e.g., for the stream abcadafga and a cache of size 2 the misses caused by a have an average distance of 2. For this experiment, we considered caches with 1024K entries and f s = 0.5, as it gave the best hit rate performance for STD v SDC (the best configuration). We separately identified the avg. miss distance of its dynamic cache from the avg. miss distance of topic caches in STD v SDC . Notice that the static cache does not impact on the analysis since it is populated by the same top-frequent queries for both STD and SDC caches. The results are shown in Fig. 6. The curves represent the avg. miss distances for the topic caches sorted by decreasing values, and we use it as a proxy of temporal locality. On the left we have Table 2: Best hit rates for SDC and different topic-cache strategies for the AOL and MSN datasets. The parameters fs, ft, and f d denote the fractions of the total cache devoted to the static, topic, and dynamic caches, respectively. The parameter f s t denotes the percentage of static cache in the topic cache. The best hit rates are highlighted in bold.

Cache Size Strategy
AOL MSN  large distances, which means that a miss occurred only when the repeated requests of that query were far away from each other. Notice that the number of topics can be lower than 500 since for some topics there are no misses. The avg. miss distances for the dynamic caches in SDC and STD are constant as they are topic-independent. These two avg. miss distances are lower when compared to those reported for most of the topic caches. It confirms that a LRU dynamic cache captures the repeated requests only if they are are close to each other (small avg. miss distance). On the other hand, topic caches have large avg. miss distances. So, the advantage of a topic cache with space divided in a proportional way among the topics is that it even serves requests distant from each other on a per-topic base, i.e., with different temporal localities.
To conclude on RQ1, the experimental results confirmed that, on equal cache sizes, the STD approach can improve SDC, resulting in an improvement of the hit rate up to ∼3.6% for AOL and ∼2% for MSN. As confirmed by simulations on two real-world query logs, the best configuration is STD v SDC (C2), although STD v LRU performs close. Moreover, this performance improvement is justified by the analysis of the avg. miss distances. In fact, in STD the misses occurring in the topic caches are caused by repeated requests that are much more distant in the query stream as compared to the misses that are encountered in SDC.
To address RQ2, and see if the improvement of STD v SDC (C2) over SDC is consistent, we compared their hit rates varying the cache size and the value of f s . Since the size of the static portion changes with f s , we split the remaining N · (1 − f s ) entries between the topic and dynamic caches using different proportions. Here, we report the results obtained with 80% for the topic cache and 20% for the dynamic cache, while the f s t parameter was set to 40%. Consistent results were observed for other parameter values. In Fig. 7, we illustrate the hit rates for the two approaches, using dashed lines for SDC and solid lines for STD v SDC (C2). Notice that we omit the hit rates for f s = 0.0 and f s = 1.0 as they correspond to completely dynamic and static caches, and the performance among the approaches are the same. If we observe the red curves for N = 64K, SDC hit rates (dashed lines) are always lower than STD v SDC hit rates (solid line). The gap of hit rates between these two caching approaches goes from ∼7% for f s = 0.1 to ∼3% for f s = 0.9 for AOL and ∼5% for f s = 0.1 to ∼2% for f s = 0.9 for MSN. As expected, the maximum improvement is registered for lower values of f s , since the impact of a topic plus a dynamic cache of STD over the only dynamic cache of SDC is more evident. We observed similar results for the other cache sizes. Regarding RQ2, we can conclude that the STD v SDC cache always outperforms the SDC cache, with an average gap of 5% for AOL and 3% for MSN, and a maximum gap of more than 5% on both query logs.
To answer to RQ3, we compared the best hit rates achieved with STD and SDC against the best hit rate that can be achieved with an optimal cache policy. We used the Bélády's optimal algorithm (also known as the clairvoyant algorithm), which always evicts the element that will not be requested for the longest time. It is not feasible in practice as it assumes to know the future requests, but it optimizes the number of hits [10], and it gives us an upper bound of the performance over which no other caching strategy can improve. We computed the gaps between Bélády hit rates and the ones achieved with the best SDC and STD configurations. The results are reported in Table 3. As we can see, the hit rates of STD are always higher than those of SDC. We report the gap between STD and SDC in the 7th column of the table and the average gap is 3.6% for AOL and 1.9% for MSN (averaged over the size of the cache). Moreover, the hit rates of STD are very close to Bélády hit rates for all cache sizes (the gap is reported in the 6th column of Table 3). The average gap between the hit rates of STD and Bélády is 6.70% for AOL and 5.06% for MSN (averaged over the size of the cache). On the other hand, the distance between SDC hit rate and Bélády hit rate is bigger (see the 5th column). The average gap between them is 10.30% for AOL and 6.98% for MSN. To quantify the gap reduction, we computed the relative delta between the two gaps (see the 8th column). It gives us an indication on how much STD improves SDC w.r.t. Bélády hit rate. To conclude on RQ3, STD hit rates achieve a significant gap reduction w.r.t. SDC from the theoretical optimal hit rate, which is up to 36.51% for AOL and up to 31.04% for MSN.
Lastly, we addressed RQ4 by implementing two admission policies to be used in conjunction with the SDC cache and the different STD configurations. The first admission policy tries to predict queries that are not worthy, namely should not be cached, also known as polluting queries [5]. The second one uses an oracle to determine the singleton queries that are not going to be requested in the future, hence they are not admitted in the cache. This allows to have an upper bound of the performance as no other admission policy can do better than the oracle which is able to see the future and determine no longer requested queries.
Caching Without Polluting Queries. Some queries are not worthy to be cached as they are not requested again or they are requested after a long period, generally after their eviction from the cache. To improve caching algorithms, researchers have tried to predict the singleton/polluting queries which are not admitted in the cache, with the purpose of preserving space for other, more promising, queries. Baeza-Yates et al. [5] analyzed stateless and stateful features for admitting queries in the cache. The stateless features do not require statistics from previous queries and can be computed on-the-fly based on the query characteristics (e.g., the query length as the number of words or characters). The assumption is that too long queries are not requested by many users, so very likely they will not appear in the future and are not worth caching. The stateful features are based on historical statistics computed over the query log, such as the number of times the query has been already requested. Other more sophisticated admission policies are based on machine learning (e.g., regression models) that predict the next query request [27]. They rely on several features of queries (e.g., query length, presence of typos), index (e.g., length of posting lists of most common or uncommon terms), query and term frequencies as well as user's sessions (e.g., user logged in, clickthrough rate). The intent is to admit to the static cache only those queries with high expected frequency and to the dynamic cache the queries with high probability to be resubmitted. The authors tried different cache configurations and showed an improvement of 0.66% for static cache and of 0.47% for SDC when their admission policy is used. We did not implement this admission policy as we lack information for index and session features, but our improvement was higher even with the admission policy based on query features (e.g., [5]). Besides, in the next paragraph, we show hit rates of STD and SDC using an oracle that prevents singleton queries from entering the cache, and this can be seen as a performance upper bound for admission techniques.
Following [5], we implemented an admission strategy that accepts a query in the cache based on stateless and stateful features. In particular, the query is cached only if it satisfies the following conditions: • it has been requested in the training period at least X times (stateful feature); • the number of terms in the query is less than Y (stateless features); • the number of characters is less than Z (stateless features); For the experiments discussed in this paper, we set X = 3, Y = 5, and Z = 20. Similar results were achieved with other threshold values proposed in [5]. For these experiments with the admission policy, we decide to use the split 30% − 70% of data in order to have more queries in the test set for the evaluation. Indeed, we observed that in the absence of polluting queries, using only 30% for test set results in a number of test queries which is too small for assessing the larger caches (e.g., 512K or 1024K entries). The results of these experiments are reported in Table 4. As we can see, the admission policy improves the hit rates of both SDC and STD caches. Note that for all configurations of cache sizes and datasets, STD outperforms SDC. Table 5 reports the gaps between hit rates achieved by SDC and by the best STD configuration with respect to the hit rates of Bélády algorithm. In all these experiments, we restrict polluting queries from entering the cache. We also computed the gap between SDC and STD (see 7th column of the table) and the gap improvement w.r.t. Bélády (see 8th column of the table). We observe that STD continues to improve SDC with larger gaps compared to the caches without admission policy (see the 7th column of Table 3), Table 4: Hit rates achieved with SDC and STD caches with an admission policy that does not admit the polluting queries into the cache. The best hit rates are highlighted in bold.

Cache
Size   Fig. 8, we show the hit rates for SDC and STD with the admission policy that does not allow caching of polluting queries. We remind the reader that the dashed lines are for SDC and solid lines for STD v SDC (C2), and we show results for the static fraction f s varying from 0.1 to 0.9. Each pair of curves represent a different size of the cache. As we can see, for the same cache size and f s value, the STD v SDC (C2) hit rate curve is always higher than the SDC curve.
Caching Without Singleton Queries. Since STD uses topical information to better cache query results, one could surmise that the STD cache capitalizes on non-singleton queries as they were observed in the training period and consequently have a topic assigned. To show that the advantage encountered with STD is irrespective of non-singleton queries, we experimented with an admission policy that restricts singleton queries from entering the cache.
A singleton query, by definition, is requested only once; hence, caching its results wastes space as the

Cache
Size query will not be requested again. We implemented an oracle (i.e., an algorithm that knows the future) which, given as input the query stream, returns the singleton queries (i.e., queries that appear only once in the stream). This is obviously not feasible in practice but does provide an optimal environment to compare STD and SDC. Then, we ran our experiments not admitting in the caches these singleton queries. As we did for the experiment on polluting queries, also for this experiment we decided to use the split 30% − 70% to have more queries in the test set. We show the results in Table 6. Again, the STD approach always improves SDC in terms of hit rates. Overall, the hit rates obtained without singleton queries are much higher as compared to those of Table 2 since not caching singleton queries spares space for future worthy queries.
In Table 7 we report the gaps between the hit rates of SDC and best STD caches with respect to Bélády as well as the gap between SDC and best STD (see the 7th column of the table). We observe that the gaps are smaller compared to the gaps of caches without admission policies (see the 7th column of Table 3), especially for large caches. This is expected, as both caches are advantaged by removing singleton queries. The gap reduction is also smaller than the one observed in the other experiments as SDC and STD perform close to the optimum. Nevertheless, this experiment proved that STD still has higher hit rates as compared Table 7: Caching with an admission policy that removes the singleton queries: Gap between the best hit rates achieved with SDC and STD caches, plus the gap reduction w.r.t. Bélády hit rate for the best hit rates achieved with the admission policy.  to SDC. We remind the reader that this admission policy is unfeasible in practice since the oracle assumes to know the future. Anyway, we included these results to show how STD improves SDC even in extreme cases where the caching approaches have the advantage of not storing singleton queries. Moreover, STD does not benefit by not storing the non-singleton queries more than SDC could do. Finally, this result is a good indication that SDC even with the best admission strategy (i.e., the oracle in our case) on the top of it cannot perform better than STD.
In Fig. 9 we show the hit rates for SDC and STD with the admission policy that does not allow caching of singleton queries. Also, for this comparison we can see that the performance of STD v SDC (C2) are always better than SDC, although the gap is lower because both remove all singleton requests getting a huge advantage for both caching strategies.

Conclusions
We presented a novel cache model, Static-Topic-Dynamic (STD) cache, which leverages query topics to better utilize cache space, yielding improved hit rates. Compared to the traditional SDC cache, the STD cache stores queries belonging to a given topic in a dedicated portion of the cache where for each topic the number of entries available is proportional to the topic popularity. This allows to capture queries that are frequently requested at large intervals of time and would be evicted in a cache only managed by the LRU policy. Extensive experiments conducted with two real-world query logs show that STD increases the cache hit rate by more than 3% over SDC. Such improvements result in a hit rate gap reduction w.r.t. Bélády's optimal caching policy [10] of up to ∼36% over SDC, depending on the query log and the total size of the cache. The improvement is even higher when an admission policy for not storing polluting queries is employed.
It is worth noting that the greater hit rate achieved by the proposed query-result cache does not require specific investments by the search engine companies. The query topic classification service is in general already deployed for other purposes [9], while our caching solution is managed entirely by software and can be easily implemented and deployed in existing Web search systems.
In the future, we would like to investigate if and how query topic classification performance impacts the cache hit ratio. We assigned topics to queries by means of a LDA classification technique trained on a portion of the query logs. We believe that improving coverage and accuracy of query classification might be beneficial for the STD cache hit ratio. As future work, we plan to employ other topic-modeling techniques which are tailored for short text [38]. We would also like to use this cache in synergy with other caches, e.g., those storing posting lists of frequently requested terms.