Add an entry into the script cache, if we reach max number of entries the * oldest is removed from the list. */
| 4570 | /* Add an entry into the script cache, if we reach max number of entries the |
| 4571 | * oldest is removed from the list. */ |
| 4572 | void replicationScriptCacheAdd(sds sha1) { |
| 4573 | int retval; |
| 4574 | sds key = sdsdup(sha1); |
| 4575 | |
| 4576 | /* Evict oldest. */ |
| 4577 | if (listLength(g_pserver->repl_scriptcache_fifo) == g_pserver->repl_scriptcache_size) |
| 4578 | { |
| 4579 | listNode *ln = listLast(g_pserver->repl_scriptcache_fifo); |
| 4580 | sds oldest = (sds)listNodeValue(ln); |
| 4581 | |
| 4582 | retval = dictDelete(g_pserver->repl_scriptcache_dict,oldest); |
| 4583 | serverAssert(retval == DICT_OK); |
| 4584 | listDelNode(g_pserver->repl_scriptcache_fifo,ln); |
| 4585 | } |
| 4586 | |
| 4587 | /* Add current. */ |
| 4588 | retval = dictAdd(g_pserver->repl_scriptcache_dict,key,NULL); |
| 4589 | listAddNodeHead(g_pserver->repl_scriptcache_fifo,key); |
| 4590 | serverAssert(retval == DICT_OK); |
| 4591 | } |
| 4592 | |
| 4593 | /* Returns non-zero if the specified entry exists inside the cache, that is, |
| 4594 | * if all the slaves are aware of this script SHA1. */ |
no test coverage detected