[squid-dev] [PATCH] cleanup external_acl_type cache

Amos Jeffries squid3 at treenet.co.nz
Wed Apr 12 01:02:16 UTC 2017


This patch begins the refactoring of the external ACL lookup cache by
replacing the LRU list of cached entries with a std::list. Removing one
more use of dlinklist.

Amos
-------------- next part --------------
=== modified file 'src/external_acl.cc'
--- src/external_acl.cc	2017-01-11 19:06:57 +0000
+++ src/external_acl.cc	2017-04-12 00:29:55 +0000
@@ -105,7 +105,7 @@
 
     hash_table *cache;
 
-    dlink_list lru_list;
+    std::list<ExternalACLEntryPointer> lru_list;
 
     int cache_size;
 
@@ -162,8 +162,8 @@
         theHelper = NULL;
     }
 
-    while (lru_list.tail) {
-        ExternalACLEntryPointer e(static_cast<ExternalACLEntry *>(lru_list.tail->data));
+    while (!lru_list.empty()) {
+        ExternalACLEntryPointer e(lru_list.front());
         external_acl_cache_delete(this, e);
     }
     if (cache)
@@ -433,7 +433,7 @@
     anEntry->def = this;
     ExternalACLEntry *e = const_cast<ExternalACLEntry *>(anEntry.getRaw()); // XXX: make hash a std::map of Pointer.
     hash_join(cache, e);
-    dlinkAdd(e, &e->lru, &lru_list);
+    lru_list.push_front(anEntry); // push front since this is LRU
     e->lock(); //cbdataReference(e); // lock it on behalf of the hash
     ++cache_entries;
 }
@@ -442,7 +442,7 @@
 external_acl::trimCache()
 {
     if (cache_size && cache_entries >= cache_size) {
-        ExternalACLEntryPointer e(static_cast<ExternalACLEntry *>(lru_list.tail->data));
+        ExternalACLEntryPointer e(lru_list.back());
         external_acl_cache_delete(this, e);
     }
 }
@@ -736,9 +736,9 @@
     if (!def->maybeCacheable(entry->result))
         return;
 
-    dlinkDelete(&entry->lru, &def->lru_list);
-    ExternalACLEntry *e = const_cast<ExternalACLEntry *>(entry.getRaw()); // XXX: make hash a std::map of Pointer.
-    dlinkAdd(e, &entry->lru, &def->lru_list);
+    const ExternalACLEntryPointer preserved(entry);
+    def->lru_list.remove(entry);
+    def->lru_list.push_front(preserved);
 }
 
 static char *
@@ -869,7 +869,7 @@
     assert(def->cache_size > 0 && entry->def == def);
     ExternalACLEntry *e = const_cast<ExternalACLEntry *>(entry.getRaw()); // XXX: make hash a std::map of Pointer.
     hash_remove_link(def->cache, e);
-    dlinkDelete(&e->lru, &def->lru_list);
+    def->lru_list.remove(entry);
     e->unlock(); // unlock on behalf of the hash
     def->cache_entries -= 1;
 }



More information about the squid-dev mailing list