Specifies that a Query should load results from a cache.
| 102 | |
| 103 | |
| 104 | class FromCache(UserDefinedOption): |
| 105 | """Specifies that a Query should load results from a cache.""" |
| 106 | |
| 107 | propagate_to_loaders = False |
| 108 | |
| 109 | def __init__( |
| 110 | self, |
| 111 | region="default", |
| 112 | cache_key=None, |
| 113 | expiration_time=None, |
| 114 | ignore_expiration=False, |
| 115 | ): |
| 116 | """Construct a new FromCache. |
| 117 | |
| 118 | :param region: the cache region. Should be a |
| 119 | region configured in the dictionary of dogpile |
| 120 | regions. |
| 121 | |
| 122 | :param cache_key: optional. A string cache key |
| 123 | that will serve as the key to the query. Use this |
| 124 | if your query has a huge amount of parameters (such |
| 125 | as when using in_()) which correspond more simply to |
| 126 | some other identifier. |
| 127 | |
| 128 | """ |
| 129 | self.region = region |
| 130 | self.cache_key = cache_key |
| 131 | self.expiration_time = expiration_time |
| 132 | self.ignore_expiration = ignore_expiration |
| 133 | |
| 134 | # this is not needed as of SQLAlchemy 1.4.28; |
| 135 | # UserDefinedOption classes no longer participate in the SQL |
| 136 | # compilation cache key |
| 137 | def _gen_cache_key(self, anon_map, bindparams): |
| 138 | return None |
| 139 | |
| 140 | def _generate_cache_key(self, statement, parameters, orm_cache): |
| 141 | """generate a cache key with which to key the results of a statement. |
| 142 | |
| 143 | This leverages the use of the SQL compilation cache key which is |
| 144 | repurposed as a SQL results key. |
| 145 | |
| 146 | """ |
| 147 | statement_cache_key = statement._generate_cache_key() |
| 148 | |
| 149 | key = statement_cache_key.to_offline_string( |
| 150 | orm_cache._statement_cache, statement, parameters |
| 151 | ) + repr(self.cache_key) |
| 152 | # print("here's our key...%s" % key) |
| 153 | return key |
| 154 | |
| 155 | |
| 156 | class RelationshipCache(FromCache): |
no outgoing calls
no test coverage detected