00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_CACHE_INTERFACE_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_CACHE_INTERFACE_H_ 00021 00022 #include "net/instaweb/util/public/shared_string.h" 00023 #include "net/instaweb/util/public/string.h" 00024 00025 namespace net_instaweb { 00026 00028 class CacheInterface { 00029 public: 00030 enum KeyState { 00031 kAvailable, 00032 kNotFound 00033 }; 00034 00035 class Callback { 00036 public: 00037 virtual ~Callback(); 00038 SharedString* value() { return &value_; } 00039 00043 bool DelegatedValidateCandidate(const GoogleString& key, KeyState state) { 00044 return ValidateCandidate(key, state); 00045 } 00046 00047 void DelegatedDone(KeyState state) { 00048 Done(state); 00049 } 00050 00051 protected: 00052 friend class CacheInterface; 00053 00067 virtual bool ValidateCandidate(const GoogleString& key, 00068 KeyState state) { return true; } 00069 00076 virtual void Done(KeyState state) = 0; 00077 00078 private: 00079 SharedString value_; 00080 }; 00081 00082 virtual ~CacheInterface(); 00083 00090 virtual void Get(const GoogleString& key, Callback* callback) = 0; 00091 00095 virtual void Put(const GoogleString& key, SharedString* value) = 0; 00096 virtual void Delete(const GoogleString& key) = 0; 00097 00099 virtual const char* Name() const = 0; 00100 00101 protected: 00103 void ValidateAndReportResult(const GoogleString& key, KeyState state, 00104 Callback* callback); 00105 }; 00106 00107 } 00108 00109 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_CACHE_INTERFACE_H_