1 #ifndef PUBSEQ_GATEWAY_CACHE_UTILS__HPP 2 #define PUBSEQ_GATEWAY_CACHE_UTILS__HPP 3 4 /* $Id: pubseq_gateway_cache_utils.hpp 629837 2021-04-22 12:47:49Z ivanov $ 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * Authors: Sergey Satskiy 30 * 31 * File Description: 32 * 33 */ 34 35 #include <objtools/pubseq_gateway/impl/cassandra/blob_record.hpp> 36 #include <objtools/pubseq_gateway/impl/cassandra/bioseq_info/record.hpp> 37 #include "pubseq_gateway_types.hpp" 38 #include "pubseq_gateway_utils.hpp" 39 #include "psgs_request.hpp" 40 41 #include <string> 42 using namespace std; 43 44 USING_IDBLOB_SCOPE; 45 46 class CPSGS_Reply; 47 48 class CPSGCache 49 { 50 public: CPSGCache(shared_ptr<CPSGS_Request> request,shared_ptr<CPSGS_Reply> reply)51 CPSGCache(shared_ptr<CPSGS_Request> request, 52 shared_ptr<CPSGS_Reply> reply) : 53 m_Allowed(false), 54 m_NeedTrace(request->NeedTrace()), 55 m_Request(request), 56 m_Reply(reply) 57 { 58 switch (request->GetRequestType()) { 59 case CPSGS_Request::ePSGS_ResolveRequest: 60 m_Allowed = 61 request->GetRequest<SPSGS_ResolveRequest>().m_UseCache != 62 SPSGS_RequestBase::ePSGS_DbOnly; 63 break; 64 case CPSGS_Request::ePSGS_BlobBySeqIdRequest: 65 m_Allowed = 66 request->GetRequest<SPSGS_BlobBySeqIdRequest>().m_UseCache != 67 SPSGS_RequestBase::ePSGS_DbOnly; 68 break; 69 case CPSGS_Request::ePSGS_BlobBySatSatKeyRequest: 70 m_Allowed = 71 request->GetRequest<SPSGS_BlobBySatSatKeyRequest>().m_UseCache != 72 SPSGS_RequestBase::ePSGS_DbOnly; 73 break; 74 case CPSGS_Request::ePSGS_AnnotationRequest: 75 m_Allowed = 76 request->GetRequest<SPSGS_AnnotRequest>().m_UseCache != 77 SPSGS_RequestBase::ePSGS_DbOnly; 78 break; 79 case CPSGS_Request::ePSGS_TSEChunkRequest: 80 m_Allowed = 81 request->GetRequest<SPSGS_TSEChunkRequest>().m_UseCache != 82 SPSGS_RequestBase::ePSGS_DbOnly; 83 break; 84 default: 85 ; 86 } 87 } 88 CPSGCache(bool allowed,shared_ptr<CPSGS_Request> request,shared_ptr<CPSGS_Reply> reply)89 CPSGCache(bool allowed, 90 shared_ptr<CPSGS_Request> request, 91 shared_ptr<CPSGS_Reply> reply) : 92 m_Allowed(allowed), 93 m_NeedTrace(request->NeedTrace()), 94 m_Request(request), 95 m_Reply(reply) 96 {} 97 IsAllowed(void) const98 bool IsAllowed(void) const 99 { 100 return m_Allowed; 101 } 102 LookupBioseqInfo(SBioseqResolution & bioseq_resolution)103 EPSGS_CacheLookupResult LookupBioseqInfo(SBioseqResolution & bioseq_resolution) 104 { 105 if (m_Allowed) 106 return x_LookupBioseqInfo(bioseq_resolution); 107 return ePSGS_CacheNotHit; 108 } 109 LookupSi2csi(SBioseqResolution & bioseq_resolution)110 EPSGS_CacheLookupResult LookupSi2csi(SBioseqResolution & bioseq_resolution) 111 { 112 if (m_Allowed) 113 return x_LookupSi2csi(bioseq_resolution); 114 return ePSGS_CacheNotHit; 115 } 116 LookupBlobProp(int sat,int sat_key,int64_t & last_modified,CBlobRecord & blob_record)117 EPSGS_CacheLookupResult LookupBlobProp(int sat, 118 int sat_key, 119 int64_t & last_modified, 120 CBlobRecord & blob_record) 121 { 122 if (m_Allowed) 123 return x_LookupBlobProp(sat, sat_key, last_modified, blob_record); 124 return ePSGS_CacheNotHit; 125 } 126 127 private: 128 EPSGS_CacheLookupResult x_LookupBioseqInfo( 129 SBioseqResolution & bioseq_resolution); 130 EPSGS_CacheLookupResult x_LookupINSDCBioseqInfo( 131 SBioseqResolution & bioseq_resolution); 132 133 EPSGS_CacheLookupResult x_LookupSi2csi( 134 SBioseqResolution & bioseq_resolution); 135 136 EPSGS_CacheLookupResult x_LookupBlobProp(int sat, 137 int sat_key, 138 int64_t & last_modified, 139 CBlobRecord & blob_record); 140 141 private: 142 bool m_Allowed; 143 bool m_NeedTrace; 144 shared_ptr<CPSGS_Request> m_Request; 145 shared_ptr<CPSGS_Reply> m_Reply; 146 }; 147 148 #endif 149