xrootd
XrdSutCache.hh
Go to the documentation of this file.
1 // $Id: XrdSutCache.hh 22437 2008-03-04 14:35:16Z rdm $
2 #ifndef __SUT_CACHE_H__
3 #define __SUT_CACHE_H__
4 /******************************************************************************/
5 /* */
6 /* X r d S u t C a c h e . h h */
7 /* */
8 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
9 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
10 /* Produced by Andrew Hanushevsky for Stanford University under contract */
11 /* DE-AC03-76-SFO0515 with the Department of Energy */
12 /******************************************************************************/
13 
14 #include <XProtocol/XPtypes.hh>
15 #include <XrdSut/XrdSutPFEntry.hh>
16 #include <XrdOuc/XrdOucHash.hh>
17 #include <XrdOuc/XrdOucString.hh>
18 #include <XrdSys/XrdSysPthread.hh>
19 
20 /******************************************************************************/
21 /* */
22 /* For caching temporary information during the authentication handshake */
23 /* */
24 /******************************************************************************/
25 
27 {
28 private:
29  XrdSysRWLock rwlock; // Access synchronizator
30  int cachesz; // Number of entries allocated
31  int cachemx; // Largest Index of allocated entries
32  XrdSutPFEntry **cachent; // Pointers to filled entries
33  kXR_int32 utime; // time at which was last updated
34  int lifetime; // lifetime (in secs) of the cache info
35  XrdOucHash<kXR_int32> hashtable; // Reflects the file index structure
36  kXR_int32 htmtime; // time at which hash table was last rebuild
37  XrdOucString pfile; // file name (if loaded from file)
38 
39 public:
40  XrdSutCache() { cachemx = -1; cachesz = 0; cachent = 0; lifetime = 300;
41  utime = -1; htmtime = -1; pfile = "";}
42  virtual ~XrdSutCache();
43 
44  // Status
45  int Entries() const { return (cachemx+1); }
46  bool Empty() const { return (cachemx == -1); }
47 
48  // Initialization methods
49  int Init(int capacity = 100, bool lock = 1);
50  int Reset(int newsz = -1, bool lock = 1);
51  int Load(const char *pfname); // build cache of a pwd file
52  int Flush(const char *pfname = 0); // flush content to pwd file
53  int Refresh(); // refresh content from source file
54  int Rehash(bool force = 0, bool lock = 1); // (re)build hash table
55  void SetLifetime(int lifet = 300) { lifetime = lifet; }
56 
57  // Cache management
58  XrdSutPFEntry *Get(int i) const { return (i<=cachemx) ? cachent[i] :
59  (XrdSutPFEntry *)0; }
60  XrdSutPFEntry *Get(const char *ID, bool *wild = 0);
61  XrdSutPFEntry *Add(const char *ID, bool force = 0);
62  bool Remove(const char *ID, int opt = 1);
63  int Trim(int lifet = 0);
64 
65  // For debug purposes
66  void Dump(const char *msg= 0);
67 };
68 
69 #endif
70