MXS-1486 When there is fresh data, update the cache entry
If something is SELECTed that should be cached for some, but not for the current user, the cached entry it nevertheless updated. That way the cached data will always be the last fetched value and it is also possible to use this behaviour for explicitly updating the cache entry.
This commit is contained in:
@ -290,11 +290,16 @@ int CacheFilterSession::routeQuery(GWBUF* pPacket)
|
||||
if (should_consult_cache(pPacket))
|
||||
{
|
||||
if (m_pCache->should_store(m_zDefaultDb, pPacket))
|
||||
{
|
||||
cache_result_t result = m_pCache->get_key(m_zDefaultDb, pPacket, &m_key);
|
||||
|
||||
if (CACHE_RESULT_IS_OK(result))
|
||||
{
|
||||
if (m_pCache->should_use(m_pSession))
|
||||
{
|
||||
uint32_t flags = CACHE_FLAGS_INCLUDE_STALE;
|
||||
GWBUF* pResponse;
|
||||
cache_result_t result = get_cached_response(pPacket, &pResponse);
|
||||
result = m_pCache->get_value(m_key, flags, &pResponse);
|
||||
|
||||
if (CACHE_RESULT_IS_OK(result))
|
||||
{
|
||||
@ -359,6 +364,23 @@ int CacheFilterSession::routeQuery(GWBUF* pPacket)
|
||||
rv = dcb->func.write(dcb, pResponse);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We will not use any value in the cache, but we will update
|
||||
// the existing value.
|
||||
if (log_decisions())
|
||||
{
|
||||
MXS_NOTICE("Unconditionally fetching data from the server, "
|
||||
"refreshing cache entry.");
|
||||
}
|
||||
m_state = CACHE_EXPECTING_RESPONSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Could not create cache key.");
|
||||
m_state = CACHE_IGNORING_RESPONSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -775,31 +797,6 @@ void CacheFilterSession::reset_response_state()
|
||||
m_res.offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route a query via the cache.
|
||||
*
|
||||
* @param key A SELECT packet.
|
||||
* @param value The result.
|
||||
* @return True if the query was satisfied from the query.
|
||||
*/
|
||||
cache_result_t CacheFilterSession::get_cached_response(const GWBUF *pQuery, GWBUF **ppResponse)
|
||||
{
|
||||
cache_result_t result = m_pCache->get_key(m_zDefaultDb, pQuery, &m_key);
|
||||
|
||||
if (CACHE_RESULT_IS_OK(result))
|
||||
{
|
||||
uint32_t flags = CACHE_FLAGS_INCLUDE_STALE;
|
||||
|
||||
result = m_pCache->get_value(m_key, flags, ppResponse);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Could not create cache key.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the data.
|
||||
*
|
||||
|
@ -102,8 +102,6 @@ private:
|
||||
|
||||
void reset_response_state();
|
||||
|
||||
cache_result_t get_cached_response(const GWBUF *pQuery, GWBUF **ppResponse);
|
||||
|
||||
bool log_decisions() const
|
||||
{
|
||||
return m_pCache->config().debug & CACHE_DEBUG_DECISIONS ? true : false;
|
||||
|
Reference in New Issue
Block a user