2 Copyright (C) 2005 Georgia Public Library Service
3 Bill Erickson <highfalutin@gmail.com>
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.
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.
19 #include <opensrf/osrf_json.h>
21 #include <opensrf/log.h>
28 osrfCache is a globally shared cache API
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
39 int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds );
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
50 int osrfCachePutObject( char* key, const jsonObject* obj, time_t seconds );
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
60 int osrfCachePutString( char* key, const char* value, time_t seconds);
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
67 jsonObject* osrfCacheGetObject( const char* key, ... );
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
74 char* osrfCacheGetString( const char* key, ... );
77 Removes the item with the given key from the cache.
78 @return 0 on success, -1 on error.
80 int osrfCacheRemove( const char* key, ... );
83 * Sets the expire time to 'seconds' for the given key
85 int osrfCacheSetExpire( time_t seconds, const char* key, ... );
90 * Clean up the global cache handles, etc.
92 void osrfCacheCleanup();