]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_cache.h
LP#1234816: improve const-correctness of osrfCachePutString and osrfCachePutObject
[OpenSRF.git] / include / opensrf / osrf_cache.h
1 /*
2 Copyright (C) 2005  Georgia Public Library Service 
3 Bill Erickson <highfalutin@gmail.com>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 */
15
16 #ifndef OSRF_CACHE_H
17 #define OSRF_CACHE_H
18
19 #include <opensrf/osrf_json.h>
20 #include <libmemcached/memcached.h>
21 #include <opensrf/log.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28   osrfCache is a globally shared cache  API
29   */
30
31
32 /**
33   Initialize the cache.
34   @param serverStrings An array of "ip:port" strings to use as cache servers
35   @param size The size of the serverStrings array
36   @param maxCacheSeconds The maximum amount of time an object / string may
37         be cached.  Negative number means there is no limit
38   */
39 int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds );
40
41
42 /**
43   Puts an object into the cache
44   @param key The cache key
45   @param obj The object to cache
46   @param seconds The amount of time to cache the data, negative number means
47         to cache up to 'maxCacheSeconds' as set by osrfCacheInit()
48   @return 0 on success, -1 on error
49   */
50 int osrfCachePutObject( const char* key, const jsonObject* obj, time_t seconds );
51
52 /**
53   Puts a string into the cache
54   @param key The cache key
55   @param value The string to cache
56   @param seconds The amount of time to cache the data, negative number means
57         to cache up to 'maxCacheSeconds' as set by osrfCacheInit()
58   @return 0 on success, -1 on error
59   */
60 int osrfCachePutString( const char* key, const char* value, time_t seconds);
61
62 /**
63   Grabs an object from the cache.
64   @param key The cache key
65   @return The object (which must be freed) if it exists, otherwise returns NULL
66   */
67 jsonObject* osrfCacheGetObject( const char* key, ... );
68
69 /**
70   Grabs a string from the cache.
71   @param key The cache key
72   @return The string (which must be freed) if it exists, otherwise returns NULL
73   */
74 char* osrfCacheGetString( const char* key, ... );
75
76 /**
77   Removes the item with the given key from the cache.
78   @return 0 on success, -1 on error.
79   */
80 int osrfCacheRemove( const char* key, ... );
81
82 /**
83  * Sets the expire time to 'seconds' for the given key
84  */
85 int osrfCacheSetExpire( time_t seconds, const char* key, ... );
86
87
88
89 /**
90  * Clean up the global cache handles, etc.
91  */
92 void osrfCacheCleanup();
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif