1/*
2 * cache-null.c: dummy caching object for Subversion
3 *
4 * ====================================================================
5 *    Licensed to the Apache Software Foundation (ASF) under one
6 *    or more contributor license agreements.  See the NOTICE file
7 *    distributed with this work for additional information
8 *    regarding copyright ownership.  The ASF licenses this file
9 *    to you under the Apache License, Version 2.0 (the
10 *    "License"); you may not use this file except in compliance
11 *    with the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 *    Unless required by applicable law or agreed to in writing,
16 *    software distributed under the License is distributed on an
17 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 *    KIND, either express or implied.  See the License for the
19 *    specific language governing permissions and limitations
20 *    under the License.
21 * ====================================================================
22 */
23
24#include "svn_private_config.h"
25#include "cache.h"
26
27/* There is no dedicated cache data structure.  Instead, we store the
28 * cache ID directly in svn_cache__t.cache_internal .
29 */
30
31static svn_error_t *
32null_cache_get(void **value_p,
33               svn_boolean_t *found,
34               void *cache_void,
35               const void *key,
36               apr_pool_t *result_pool)
37{
38  /* We know there is nothing to be found in this cache. */
39  *value_p = NULL;
40  *found = FALSE;
41
42  return SVN_NO_ERROR;
43}
44
45static svn_error_t *
46null_cache_has_key(svn_boolean_t *found,
47                   void *cache_void,
48                   const void *key,
49                   apr_pool_t *scratch_pool)
50{
51  /* We know there is nothing to be found in this cache. */
52  *found = FALSE;
53  return SVN_NO_ERROR;
54}
55
56static svn_error_t *
57null_cache_set(void *cache_void,
58               const void *key,
59               void *value,
60               apr_pool_t *scratch_pool)
61{
62  /* We won't cache anything. */
63  return SVN_NO_ERROR;
64}
65
66static svn_error_t *
67null_cache_iter(svn_boolean_t *completed,
68                void *cache_void,
69                svn_iter_apr_hash_cb_t user_cb,
70                void *user_baton,
71                apr_pool_t *scratch_pool)
72{
73  /* Iteration over an empty set is a no-op. */
74  if (completed)
75    *completed = TRUE;
76
77  return SVN_NO_ERROR;
78}
79
80static svn_error_t *
81null_cache_get_partial(void **value_p,
82                       svn_boolean_t *found,
83                       void *cache_void,
84                       const void *key,
85                       svn_cache__partial_getter_func_t func,
86                       void *baton,
87                       apr_pool_t *result_pool)
88{
89  /* We know there is nothing to be found in this cache. */
90  *found = FALSE;
91  return SVN_NO_ERROR;
92}
93
94static svn_error_t *
95null_cache_set_partial(void *cache_void,
96                       const void *key,
97                       svn_cache__partial_setter_func_t func,
98                       void *baton,
99                       apr_pool_t *scratch_pool)
100{
101  /* We know there is nothing to update in this cache. */
102  return SVN_NO_ERROR;
103}
104
105static svn_boolean_t
106null_cache_is_cachable(void *cache_void,
107                       apr_size_t size)
108{
109  /* We won't cache anything */
110  return FALSE;
111}
112
113static svn_error_t *
114null_cache_get_info(void *cache_void,
115                    svn_cache__info_t *info,
116                    svn_boolean_t reset,
117                    apr_pool_t *result_pool)
118{
119  const char *id = cache_void;
120
121  info->id = apr_pstrdup(result_pool, id);
122
123  info->used_entries = 0;
124  info->total_entries = 0;
125
126  info->used_size = 0;
127  info->data_size = 0;
128  info->total_size = 0;
129
130  return SVN_NO_ERROR;
131}
132
133static svn_cache__vtable_t null_cache_vtable = {
134  null_cache_get,
135  null_cache_has_key,
136  null_cache_set,
137  null_cache_iter,
138  null_cache_is_cachable,
139  null_cache_get_partial,
140  null_cache_set_partial,
141  null_cache_get_info
142};
143
144svn_error_t *
145svn_cache__create_null(svn_cache__t **cache_p,
146                       const char *id,
147                       apr_pool_t *result_pool)
148{
149  svn_cache__t *cache = apr_pcalloc(result_pool, sizeof(*cache));
150  cache->vtable = &null_cache_vtable;
151  cache->cache_internal = apr_pstrdup(result_pool, id);
152  cache->pretend_empty = FALSE; /* There is no point in pretending --
153                                   this cache _is_ empty. */
154
155  *cache_p = cache;
156  return SVN_NO_ERROR;
157}
158