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