]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_cache.h
Prepare for #inclusion in C++ programs
[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
17 #include <opensrf/osrf_json.h>
18 #include <memcache.h>
19 #include <opensrf/log.h>
20
21 /**
22   osrfCache is a globally shared cache  API
23   */
24
25
26 /**
27   Initialize the cache.
28   @param serverStrings An array of "ip:port" strings to use as cache servers
29   @param size The size of the serverStrings array
30   @param maxCacheSeconds The maximum amount of time an object / string may
31         be cached.  Negative number means there is no limit
32   */
33 int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds );
34
35
36 /**
37   Puts an object into the cache
38   @param key The cache key
39   @param obj The object to cache
40   @param seconds The amount of time to cache the data, negative number means
41         to cache up to 'maxCacheSeconds' as set by osrfCacheInit()
42   @return 0 on success, -1 on error
43   */
44 int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds );
45
46 /**
47   Puts a string into the cache
48   @param key The cache key
49   @param value The string to cache
50   @param seconds The amount of time to cache the data, negative number means
51         to cache up to 'maxCacheSeconds' as set by osrfCacheInit()
52   @return 0 on success, -1 on error
53   */
54 int osrfCachePutString( char* key, const char* value, time_t seconds);
55
56 /**
57   Grabs an object from the cache.
58   @param key The cache key
59   @return The object (which must be freed) if it exists, otherwise returns NULL
60   */
61 jsonObject* osrfCacheGetObject( const char* key, ... );
62
63 /**
64   Grabs a string from the cache.
65   @param key The cache key
66   @return The string (which must be freed) if it exists, otherwise returns NULL
67   */
68 char* osrfCacheGetString( const char* key, ... );
69
70 /**
71   Removes the item with the given key from the cache.
72   @return 0 on success, -1 on error.
73   */
74 int osrfCacheRemove( const char* key, ... );
75
76 /**
77  * Sets the expire time to 'seconds' for the given key
78  */
79 int osrfCacheSetExpire( time_t seconds, const char* key, ... );
80
81
82
83 /**
84  * Clean up the global cache handles, etc.
85  */
86 void osrfCacheCleanup();