Drizzled Public API Documentation

memcached_qc.h

00001 /* 
00002  * Copyright (C) 2010 Djellel Eddine Difallah
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *   * Redistributions of source code must retain the above copyright notice,
00009  *     this list of conditions and the following disclaimer.
00010  *   * Redistributions in binary form must reproduce the above copyright notice,
00011  *     this list of conditions and the following disclaimer in the documentation
00012  *     and/or other materials provided with the distribution.
00013  *   * Neither the name of Djellel Eddine Difallah nor the names of its contributors
00014  *     may be used to endorse or promote products derived from this software
00015  *     without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027  * THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 #pragma once
00030 
00031 #include <drizzled/plugin/query_cache.h>
00032 #include "query_cache_service.h"
00033 #include <drizzled/atomics.h>
00034 #include <libmemcached/memcached.hpp>
00035 
00036 namespace drizzled 
00037 {
00038   class Session;
00039   class select_result;
00040   class String;
00041   class TableList;
00042 }
00043 class MemcachedQueryCache : public drizzled::plugin::QueryCache
00044 {
00045 private:
00046   pthread_mutex_t mutex;  
00047   drizzled::QueryCacheService queryCacheService;
00048   static memcache::Memcache* client;
00049   static std::string memcached_servers;
00050 
00051 public:
00052   
00053   explicit MemcachedQueryCache(std::string name_arg, const std::string &servers_arg): drizzled::plugin::QueryCache(name_arg)
00054   {
00055     client= new memcache::Memcache(servers_arg);
00056     pthread_mutex_init(&mutex, NULL);
00057     queryCacheService= drizzled::QueryCacheService::singleton();
00058   }
00059   ~MemcachedQueryCache()
00060   {
00061     delete client;
00062     pthread_mutex_destroy(&mutex);
00063   };
00064   bool doIsCached(drizzled::Session *session);
00065   bool doSendCachedResultset(drizzled::Session *session);
00066   bool doPrepareResultset(drizzled::Session *session);
00067   bool doInsertRecord(drizzled::Session *session, drizzled::List<drizzled::Item> &item);
00068   bool doSetResultset(drizzled::Session *session);
00069   char* md5_key(const char* str);
00070   void checkTables(drizzled::Session *session, drizzled::TableList* in_table);
00071   bool isSelect(std::string query);
00072   static memcache::Memcache* getClient()
00073   {
00074     return client;
00075   }
00076   static const char *getServers()
00077   {
00078     return memcached_servers.c_str();
00079   }
00080   static void setServers(const std::string &server_list)
00081   {
00082     memcached_servers.assign(server_list);
00083     //getClient()->setServers(server_list);
00084   }
00085 
00086 };