201222286 六、發明說明: 【發明所屬之技術領域】 本發明涉及網路技術領域,尤其涉及一種分散式快取 的物件刪除方法、系統及刪除伺服器。 【先前技術】 大型網站系統通常採用分散式快取結構對資料進行存 取’例如’淘寶網(taobao.com )利用分散式快取結構對 用戶所上傳的圖片進行存取。在分散式快取系統中,通常 包含一個源資料伺服器和若干與該源資料伺服器進行通信 的快取伺服器,以及一個調度器。分散式快取系統在回應 用戶請求時,通常由調度器根據接收到的用戶請求,藉由 一致性哈希調度演算法計算出該用戶需要從哪台快取伺服 器上獲取資料,如果計算出的快取伺服器存在要獲取的資 料,則將該資料返回調度器;如果計算出的快取伺服器不 存在要獲取的資料,則向源資料伺服器索取該資料並將該 資料保存在本機,同時將該資料返回給調度器,由調度器 將資料返回給用戶。 在現有的分散式快取系統中,以淘寶網的圖片系統爲 例,賣家向網站上傳了 一張惡意圖片,例如涉及侵權或者 違法的圖片,該惡意圖片首先上傳到源圖片伺服器。當網 路用戶藉由淘寶網的鏈結訪問該惡意圖片時,首先會訪問 藉由一致性哈希演算法計算出的某台圖片快取伺服器,若 該圖片快取伺服器上還未儲存該惡意圖片,該圖片快取伺 -5- 201222286 服器將從源圖片伺服器獲取該惡意圖片並保存。當一旦發 現系統中存在惡意圖片時,就需要對該惡意圖片進行刪除 操作。現有技術中在刪除惡意圖片時,在分散式快取系統 中的源圖片伺服器和所有圖片快取伺服器上執行刪除該惡 意圖片的操作。 發明人在對現有技術的硏究過程中發現,現有技術中 的刪除方式由於需要在所有伺服器上執行刪除操作,但是 並非所有的快取伺服器上都存在惡意資料,因此,這樣的 操作方式將極大地增加伺服器的負擔,浪費伺服器資源, 特別是對於包含大量快取伺服器的系統來說,不存在惡意 資料的快取伺服器均要執行多餘的刪除操作,這降低了分 散式快取系統的整體性能。 【發明內容】 本發明實施例的目的是提供一種分散式快取的物件刪 除方法、系統及刪除伺服器,以解決現有技術中所有分散 式快取伺服器都需要執行刪除操作浪費伺服器資源,導致 系統性能降低的問題。 爲解決上述技術問題,本發明實施例提供了一種分散 式快取的物件刪除方法,是這樣實現的: 一種分散式快取的物件刪除方法,包括: 接收刪除請求,所述刪除請求中包含物件的識別字: 藉由對所述物件的識別字進行一致性哈希計算得到所 述識別字的哈希結果値; -6- 201222286 根據所述哈希結果値定位到對應的快取伺服器,將所 述對應的快取伺服器作爲當前快取伺服器; 判斷所述當前快取伺服器是否處於活躍狀態且活躍時 間大於所述物件的過期時間; 當判斷當前快取伺服器處於活躍狀態且所述活躍時間 大於所述物件的過期時間時,從所述當前快取伺服器上刪 除所述物件。 爲解決上述技術問題,本發明實施例提供了一種分散 式快取的物件刪除系統,是這樣實現的: 一種分散式快取的物件刪除系統,包括:刪除伺服器 和若干快取伺服器, 所述快取伺服器,用戶快取用戶訪問的物件; 所述刪除伺服器,用於接收刪除請求,所述刪除請求 中包含物件的識別字,藉由對所述物件的識別字進行一致 性哈希計算得到所述識別字的哈希結果値,根據所述哈希 結果値定位到對應的快取伺服器,將所述對應的快取伺服 器作爲當前快取伺服器,判斷所述當前快取伺服器是否處 於活躍狀態且活躍時間大於所述物件的過期時間,當判斷 當前快取伺服器處於活躍狀態且所述活躍時間大於所述物 件的過期時間時,從所述當前快取伺服器上删除所述物件 〇 爲解決上述技術問題,本發明實施例還提供了 一種刪 除伺服器,是這樣實現的: 一種刪除伺服器,包括: 201222286 接收單元,用於接收刪除請求,所述删除請求中包含 物件的識別字; 計算單元,用於藉由對所述物件的識別字進行一致性 哈希計算得到所述識別字的哈希結果値; 定位單元,用於根據所述哈希結果値定位到對應的快 取伺服器’將所述對應的快取伺服器作爲當前快取伺服器 i 判斷單元,用於判斷所述當前快取伺服器是否處於活 躍狀態且活躍時間大於所述物件的過期時間; 刪除單元,用於當判斷當前快取伺服器處於活躍狀態 且所述活躍時間大於所述物件的過期時間時,從所述當前 快取伺服器上刪除所述物件。 可見,本發明實施例中接收包含物件的識別字的刪除 請求,藉由對物件的識別字進行一致性哈希計算得到哈希 結果値,根據哈希結果値定位到對應的快取伺服器,將對 應的快取伺服器作爲當前快取伺服器,判斷當前快取伺服 器是否處於活躍狀態且活躍時間大於物件的過期時間,當 判斷當前快取伺服器處於活躍狀態且活躍時間大於物件的 過期時間時,從當前快取伺服器上刪除所述物件。由此可 知,本發明實施例中無需在所有快取伺服器上執行刪除物 件的操作,而是藉由比較所定位快取伺服器的活躍時間和 物件的過期時間,精確定位到包含待刪除物件的快取伺服 器,並執行刪除操作,由此節約了其他快取伺服器爲執行 刪除操作所要耗費的資源,提高了分散式快取系統的整體 -8 - 201222286 性能。 【實施方式】 本發明實施例提供一種分散式快取的物件刪除方法、 系統及刪除伺服器。 爲了使本技術領域的人員更好地理解本發明實施例中 的技術方案,並使本發明實施例的上述目的、特徵和優點 能夠更加明顯易懂,下面結合附圖對本發明實施例中技術 方案作進一步詳細的說明。 本發明實施例中對分散式快取系統中物件的刪除基於 該系統中分散式快取伺服器上已經儲存的物件。因此,下 面首先結合一致性哈希演算法描述一下現有系統中物件如 何在分散式快取伺服器上進行存取。 分散式快取系統中,藉由一致性哈希演算法計算後的 快取伺服器將根據其哈希値的大小配置在一個0至2的 3 2次方的圓環上。在計算快取伺服器的哈希値時,將每 個快取伺服器的IP位址藉由選定的哈希函數進行計算得 到一個哈希値,該哈希値爲一個32位元的整數,根據該 整數的大小將其對應的快取伺服器映射在圓環上的相應位 置。參見圖1,爲一個0至2的32次方的圓環示例,假 設分散式快取系統中包含四個快取伺服器,則經過一致性 哈希計算後,四個快取伺服器根據其哈希値的大小如圖1 所示映射在圓環上,順時針依次爲快取伺服器1、快取伺 服器2、快取伺服器3和快取伺服器4 ;當用戶想要藉由 201222286 分散式快取伺服器訪問某個物件時(物件可以爲圖片、音 視頻等網路資源),對該物件進行哈希計算(通常對物件 的識別字URL進行哈希計算),將得到的哈希値作爲鍵 値,根據該鍵値的大小將其映射到0至2的3 2次方的圓 環上的相應位置,並將該鍵値所在的位置作爲起始位置, 在圓環上順時針査找到第一個快取伺服器,用戶藉由該査 找到的第一個快取伺服器訪問所要訪問的物件,如果順時 針查找到的第一個快取伺服器不可用(例如宕機),則繼 續順時針査找,直到找到一個可用的快取伺服器。如果找 到的可用快取伺服器上存在用戶要訪問的物件,則將該物 件藉由調度伺服器返回給用戶,如果找到的可用快取伺服 器上不存在用戶要訪問的物件,則該快取伺服器向源資料 伺服器索取該物件並將該物件保存在本機上,同時將該物 件返回給調度伺服器,由調度伺服器將物件返回給用戶。 儲存在快取伺服器上的每個物件都有其過期時間,當 物件的快取時間超過過期時間時,快取伺服器將自動刪除 該物件。此後當用戶再次藉由該快取伺服器訪問該物件時 ,則可以重新從源資料伺服器上獲取該物件,並重複執行 前述流程。 參見圖2,爲本發明分散式快取的物件刪除方法的第 —實施例流程圖,該實施例僅示出了所定位的快取伺服器 的活躍時間大於待刪除物件的存活時間時的物件删除過程 步驟2 0 1 :接收刪除請求,該刪除請求中包含物件的 -10- 201222286 識別字。 當分散式快取系統應用在大型網站時,物件具體指圖 片、音視頻等網路資源,每一個具體的網路資源藉由URL (Universal Resource Locator,統一資源定位符)進行定 位。 步驟202 :藉由對物件的識別字進行一致性哈希計算 得到識別字的哈希結果値。 本步驟中對物件的識別字進行一致性哈希計算得到哈 希結果値的過程,與現有技術中爲實現物件的存取所進行 的計算過程一致,在此不再贅述。 步驟2 0 3 :根據哈希結果値定位到對應的快取伺服器 ’將該對應的快取伺服器作爲當前快取伺服器。 結合圖1所示的一致性哈希圓環可知,對物件的識別 字進行一致性哈希計算並獲得哈希結果値後,可以將該哈 希結果値作爲鍵値映射到一致性哈希圓環上的相應位置, 並從該位置開始順時針查找第一個快取伺服器,由於該查 找到的第一個快取伺服器即爲用戶要訪問該物件時所調度 的快取伺服器’因此該第一個快取伺服器在活躍狀態下, 並且有用戶訪問該物件且該物件的過期時間未超過時,必 然快取了待刪除的物件。 步驟204:判斷當前快取伺服器是否處於活躍狀態且 活躍時間大於物件的過期時間。 步驟205 :當判斷當前快取伺服器處於活躍狀態且活 足翟時間大於物件的過期時間時,從當前快取伺服器上刪除 -11 - 201222286 該物件。 活躍時間指快取伺服器處於活躍狀態的持續時間,當 所定位的第一個快取伺服器處於活躍狀態’且活躍時間大 於物件的過期時間,則由於該快取伺服器當前活躍,則所 有訪問物件的請求都將發送到該快取伺服器’而其他快取 伺服器上即使存在過該物件,也會因爲存在時間超過了物 件的過期時間而被自動刪除,此時只需要在所定位的第一 個快取伺服器上執行刪除URL的操作即可。 參見圖3,爲本發明分散式快取的物件刪除方法的第 二實施例流程圖,該實施例詳細示出了根據所定位快取伺 服器的活躍狀態及狀態歷史資訊實現物件刪除的過程: 步驟3 0 1 :預先建立快取伺服器的狀態表,並藉由狀 態表保存每一個快取伺服器最後一次發生狀態變化時的時 間戳記,以及每一個快取伺服器的當前狀態。 本發明實施例中建立快取伺服器的狀態表,狀態表的 每一個表項用於記錄一個快取伺服器最後一次發生狀態變 化時的時間戳記,以及每一個快取伺服器的當前狀態。其 中,藉由時間戳記可以確定快取伺服器當前狀態的持續時 間,當前狀態可以包括活躍狀態和非活躍狀態,非活躍狀 態通常指快取伺服器發生宕機。 步驟302:接收刪除請求,該刪除請求中包含物件的 識別字。 步驟3 0 3 :藉由對物件的識別字進行一致性哈希計算 得到識別字的哈希結果値。 -12- 201222286 步驟3 04 :根據哈希結果値定位到對應的快取伺服器 ,將對應的快取伺服器作爲當前快取伺服器。 步驟305 :判斷當前快取伺服器是否處於活躍狀態, 若是,則執行步驟306 ;否則,執行步驟309。 步驟306 :判斷當前快取伺服器的活躍時間是否大於 物件的過期時間,若是,則執行步驟3 07 ;否則,執行步 驟 3 08。 步驟3 07 :從當前快取伺服器上刪除該物件,結束當 前流程。 當根據狀態表查找到當前快取伺服器處於活躍狀態, 且活躍時間大於物件的過期時間,則由於該快取伺服器當 前活躍,所有訪問該物件的請求都將發送到該快取伺服器 ,而其他快取伺服器上即使存在過該物件,也會因爲存在 時間超過了物件的過期時間而被自動刪除,此時只需要在 所定位的第一個快取伺服器上執行刪除URL的操作即可 〇 步驟3 0 8 :從當前快取伺服器上刪除該物件,從當前 快取伺服器順序遷移到下一台快取伺服器,並將下一台快 取伺服器作爲當前快取伺服器,返回步驟305。 當根據狀態表查找到當前快取伺服器處於活躍狀態, 且根據其時間戳記的記載判斷其活躍時間小於物件的過期 時間,則首先從快取伺服器上刪除該物件;然後,考慮到 假如該快取伺服器在活躍狀態之前爲非活躍狀態,則該快 取伺服器處於非活躍狀態時,訪問該待刪除物件的請求可 -13- 201222286 能順序遷移到一致性哈希圓環上該當前 台快取伺服器’使得下一台快取伺服器 物件,因此需要順序獲取下一台快取伺 台快取伺服器作爲當前快取伺服器,重 斷,因此返回步驟3 05。 步驟309 :判斷當前快取伺服器的 於物件的過期時間,若是,則執行步驟 步驟3 1 1。 步驟3 1 0 :從當前快取伺服器順序 伺服器,並將下一台快取伺服器作爲當 回步驟3 0 5。 當根據狀態表査找到當前快取伺服 ,且根據其時間戳記的記載判斷其非活 過期時間,則在當前快取伺服器的非活 除物件的訪問可能順序遷移到一致性哈 取伺服器的下一台快取伺服器,使得下 也可能快取了該物件,因此需要順序獲 器,並將該下一台快取伺服器作爲當前 對其狀態進行判斷,因此返回步驟3 0 5 而對於原來非活躍時間大於物件的 服器來說,當其一旦恢復到活躍狀態, 件的過期時間,因此該快取伺服器會自 除操作。 步驟3 1 1 :記錄該物件的識別字, 快取伺服器的下一 上也可能快取了該 服器,並將該下一 新對其狀態進行判 非活躍時間是否大 3 1 0 ;否則,執行 遷移到下一台快取 前快取伺服器,返 器處於非活躍狀態 躍時間大於物件的 躍時間內,對待刪 希圓環上該當前快 一台快取伺服器上 取下一台快取伺服 快取伺服器,重新 〇 過期時間的快取伺 由於已經超過了物 動執行對物件的删 從當前快取伺服器 -14- 201222286 順序遷移到下一台快取伺服器,並將下一台快 爲當前快取伺服器,返回步驟3 0 5 » 當根據狀態表查找到當前快取伺服器處於 ’且根據其時間戳記的記載判斷其非活躍時間 過期時間’則在當前快取伺服器的非活躍時間 除物件的訪問可能順序遷移到一致性哈希圓環 取伺服器的下一台快取伺服器,使得下一台快 也可能快取了該物件,因此需要順序獲取下一 器’並將該下一台快取伺服器作爲當前快取伺 對其狀態進行判斷,因此返回步驟3 0 5。 而對於原來非活躍時間小於物件的過期時 服器來說,需要同時記錄該待刪除物件的識別 該快取伺服器在小於物件的過期時間內恢復到 ,可以根據記錄的識別字刪除該物件。 參見圖4,爲應用本發明分散式快取的物 實施例的一種系統結構示意圖:該系統結構中 資料伺服器,N個快取伺服器(N爲正整數) 伺服器和一個刪除代理伺服器。其中,刪除代 本發明實施例爲了實現對分散式快取的物件進 加的伺服器,而源資料伺服器、快取伺服器和 仍然按照現有方式實現資料在分散式快取系統 程。 其中,調度伺服器(也可稱爲負載t haproxy )接收用戶的物件訪問請求,並根據 取伺服器作 非活躍狀態 小於物件的 內,對待刪 上該當前快 取伺服器上 台快取伺服 服器,重新 間的快取伺 字,以便當 活躍狀態時 件刪除方法 包括一個源 ,一個調度 理伺服器爲 行刪除所增 調度伺服器 中的存取過 3衡調度器 一致性哈希 -15- 201222286 演算法調度某個快取伺服器,調度過程與前述對現有技術 的描述過程一致,在此不再贅述。 快取伺服器(可以藉由在伺服器上承載開源快取服務 程式squid實現)接收調度伺服器的調度請求,從本機快 取中返回用戶要訪問的物件,或者從源資料伺服器中獲取 並返回用戶要訪問的物件。 刪除代理伺服器(purge agent)爲本發明系統結構中 增加的伺服器,其採用與調度伺服器同樣的一致性哈希演 算法,實現對快取物件的刪除。該刪除代理伺服器可以是 一台獨立的伺服器,或者也可以整合在某個快取伺服器中 ,由該快取伺服器同時執行刪除功能,刪除代理伺服器可 以與系統中的所有快取伺服器進行通信。系統中的物件刪 除請求會傳輸到該刪除代理伺服器,例如,當監測到惡意 圖片需要刪除,或者某個商品退市時其圖片也需要刪除, 此時向該刪除代理伺服器發送刪除請求,該刪除請求中包 含待刪除物件的識別字(例如,惡意圖片的鏈結位址)。 同時,刪除代理伺服器上還維護一個包含所有快取伺服器 的狀態資訊的狀態表,該狀態表中記錄了每個快取伺服器 的兩條資訊,一條資訊是快取伺服器最後一次發生狀態變 化的時間戳記(藉由該時間戳記可以計算快取伺服器最後 一次狀態變化的持續時間),另一條資訊是快取伺服器的 當前狀態,藉由該當前狀態可以判斷快取伺服器當前處於 活躍狀態還是宕機狀態。 假設待刪除物件的識別字爲url_a,則結合圖1的一 -16- 201222286 致性哈希圓環對本發明實施例的刪除過程進行描述。 url_a代表一個網站資源,通常爲物件的鏈結位址,當確 定要刪除url_a後,首先在源資料伺服器上刪除該物件, 然後刪除快取何服器上存在的Url_a。此時,對url_a進 行一致性哈希計算後,確定要訪問url_a則首先對應到一 致性哈希圓環上的快取伺服器1,然後査找狀態表,其處 理流程如圖5所示: 步驟501 :接收包含uri_a的物件刪除請求。 步驟5 02 :根據一致性哈希計算確定訪問url_a需要 調度的快取伺服器1。 步驟5 03 :判斷當前調度的快取伺服器是否處於活躍 狀態’並且其活躍時間大於物件url_a的過期時間,若是 ,則執行步驟5 0 4 ;否則,執行步驟5 0 5。 步驟504 :在當前調度的快取伺服器上刪除物件 url_a,結束當前流程。 如果查找到快取伺服器1的當前狀態爲“活躍”,且 根據其時間戳記的記載判斷其活躍時間大於url_a的過期 時間’則說明無論該快取伺服器1是否宕機過,由於該快 取伺服器1當前活躍,則所有訪問url_a的請求都將發送 到快取伺服器1,而其他快取伺服器上即使存在該物件 url_a,也會因爲存在時間超過了 url_a的過期時間而被自 動刪除,此時只需要在快取伺服器1上執行刪除url的操 作即可。 步驟5 0 5 :判斷當前調度的快取伺服器是否仍然處於 -17- 201222286 宕機狀態,若是’則執行步驟5 0 6 ;否則,執行步驟5 0 8 〇 步驟506:判斷當前處於宕機狀態的快取伺服器的宕 機時長是否超過物件url_a的過期時間,若是,則執行步 驟5 09 ;否則,執行步驟507。 如果查找到快取伺服器1的當前狀態爲"宕機”,且 根據其時間戳記的記載判斷其宕機時長超過物件url_a的 過期時間,則在快取伺服器1 “宕機”時間內,對物件 url_a的訪問可能順序遷移到快取伺服器2至快取伺服器 4中的任意一台,因此需要順序獲取下一台快取伺服器, 並對該快取伺服器重複從步驟503開始執行;而對於快取 伺服器1本身,當其一旦恢復活躍狀態,由於已經超過物 件url_a的過期時間,因此快取伺服器1會自動執行對物 件url_a的刪除操作。 步驟507 :保存當前快取伺服器及物件url_a,執行 步驟5 0 9。 如果查找到快取伺服器1的當前狀態爲"宕機”,且 根據其時間戳記的記載判斷其宕機時長小於物件url_a的 過期時間,則在快取伺服器1 “宕機”時間內,對物件 url_a的訪問可能順序遷移到快取伺服器2至快取伺服器 4中的任意一台’因此需要順序獲取下一台快取伺服器, 並對該快取伺服器重複從步驟503開始執行:而由於快取 伺服器1的宕機時長小於物件url-a的過期時間’因此需 要同時記錄該物件的url_a ’以便當快取伺服器1在小於 -18- 201222286 物件url_a的過期時間內恢復活躍狀態時,可以根據該記 錄刪除物件url_a » 其中,可以將當前快取伺服器1和物件的url_a的對 應關係保存到延遲刪除列表中,當快取伺服器1在小於物 件url_a的過期時間內恢復活躍狀態時,根據該延遲刪除 列表中記錄的表項刪除該快取伺服器1上的物件url_a。 步驟5 08 :在當前快取伺服器上刪除物件url_a。 如果査找到快取伺服器1的當前狀態爲“活躍”,且 根據其時間戳記的記載判斷其活躍時間小於url_a的過期 時間,則首先從快取伺服器1上刪除url_a ;然後,考慮 到假如快取伺服器1在“活躍”狀態之前爲“宕機”狀態 ’則快取伺服器1在“宕機”狀態時,訪問url_a的請求 可能順序遷移到快取伺服器2至快取伺服器4中的任意一 台,因此需要順序獲取下一台快取伺服器,並對該快取伺 服器重複從步驟5 0 3開始執行。 步驟5 0 9 :判斷是否能夠從當前快取伺服器映射到下 —個快取伺服器’若是,則執行步驟5 1 0 ;否則,結束當 前流程。 步驟5 1 0 :順序從當前快取伺服器映射到下—個快取 伺服器,返回步驟503。 由此可見,本發明實施例中,刪除代理伺服器保持與 調度伺服器相同的一致性哈希演算法,藉由結合快取伺服 器的狀態變化資訊’對待刪除物件所在的快取伺服器進行 精確定位’由於能準確全面地刪除物件,而無需對所有快 -19- 201222286 取伺服器都執行刪除操作,因此與現有技術相比,減少了 在系統中所有快.取伺服器上執行刪除操作所佔用的系統資 源。 下面結合圖6,藉由分散式快取圖片系統中對惡意圖 片進行刪除爲例描述本發明實施例的實現過程: 假設分散式快取系統中包含三個快取伺服器,分別爲 S 1、S 2和S 3,每個快取伺服器以其IP位址爲標識進行識 別,藉由選定的哈希函數hash_fuction_x將對SI、S2和 S3的IP位址分別進行哈希計算,假設得到的哈希値爲三 個整數,分別爲1〇〇〇、2000、3 000 ’則這三個快取伺服 器在圓環上的映射位置如圖3A所示,並且,假設這三個 快取伺服器初始時刻的狀態表如下表1所示,其中 Last_stamp表示快取伺服器最後一次發生狀態變化時的時 間戳記,Currentjtatus表示快取伺服器的當前狀態: 表1 伺服器 SI S2 S3 Last stamp 0 0 0 Current status Up Up Up 上表1中,SI、S2和S3在初始時刻的Last_stamp爲 “ 0” ,表示在初始時刻S1、S2和S3的時間戳記均爲〇 ,時間戳記可以以“天”爲單位進行記錄,例如,初始開 機爲第一天,則時間戳記爲“ ” ,後續每過一天,時間 戳記的値順序增加1 ; Current_status爲“ UP” ’表示Si •20- 201222286 、S2 和 S3 在初始時刻都處於活躍狀態,當 Current_status爲“DOWN”時,表示處於若機狀態。 假設在時刻1,用戶想要訪問物件資源url_l,對該 url_l藉由哈希函數hash_fuction_x計算後,得到的哈希 値爲2 5 3,將該哈希値映射到圖3 A所示的圓環上,從哈 希値2 5 3映射的位置開始順時針査找到的第一個快取伺服 器爲S 1,因此訪問物件資源url_ 1的請求由S 1進行處理 ,假設用戶第一次藉由S1訪問url_l,則S1從源伺服器 獲取該物件資源url_l,保存該url_l並將該url_l返回給 客戶。 假設在時刻2,S 1發生宕機,則此時更新快取伺服器 的狀態表,如下表2所不:201222286 VI. Description of the Invention: [Technical Field] The present invention relates to the field of network technologies, and in particular, to a method, system and deletion server for decentralized cache deletion. [Prior Art] Large-scale website systems usually use a decentralized cache structure to access data. For example, taobao.com uses a decentralized cache structure to access images uploaded by users. In a decentralized cache system, it typically includes a source data server and a number of cache servers that communicate with the source data server, and a scheduler. When the decentralized cache system responds to a user request, the scheduler usually calculates the information from which cache server the user needs to obtain from the cache server according to the received user request. If the cache server has the data to be obtained, the data is returned to the scheduler; if the calculated cache server does not have the data to be acquired, the data is requested from the source data server and the data is saved in the program. The machine returns the data to the scheduler, and the scheduler returns the data to the user. In the existing distributed cache system, taking Taobao's image system as an example, the seller uploaded a malicious image to the website, for example, an image involving infringement or illegality, and the malicious image is first uploaded to the source image server. When a web user accesses the malicious picture through the link of Taobao, first accesses an image cache server calculated by the consistent hash algorithm, if the image cache server has not yet been Save the malicious image, the image cache server - 201222286 server will get the malicious image from the source image server and save. When a malicious picture is found in the system, the malicious picture needs to be deleted. In the prior art, when a malicious picture is deleted, the operation of deleting the malicious picture is performed on the source picture server and all the picture cache servers in the distributed cache system. The inventor found in the prior art research process that the deletion method in the prior art needs to perform deletion operations on all servers, but not all cache servers have malicious data, so such operation mode It will greatly increase the burden on the server and waste server resources. Especially for systems with a large number of cache servers, cache servers that do not have malicious data must perform redundant deletion operations, which reduces the decentralized The overall performance of the cache system. SUMMARY OF THE INVENTION An object of the present invention is to provide a decentralized cached object deletion method, system, and deletion server, to solve the problem that all decentralized cache servers in the prior art need to perform a delete operation to waste server resources. A problem that causes system performance to degrade. In order to solve the above technical problem, an embodiment of the present invention provides a decentralized cache object deletion method, which is implemented as follows: A decentralized cache object deletion method, comprising: receiving a deletion request, wherein the deletion request includes an object The identification word: the hash result of the identification word is obtained by performing a consistent hash calculation on the identification word of the object; -6- 201222286 according to the hash result, positioning to the corresponding cache server, Determining whether the current cache server is in an active state and the active time is greater than an expiration time of the object; determining that the current cache server is active and When the active time is greater than the expiration time of the object, the object is deleted from the current cache server. In order to solve the above technical problem, an embodiment of the present invention provides a decentralized cache object deletion system, which is implemented as follows: A decentralized cache object deletion system, comprising: deleting a server and a plurality of cache servers, The cache server, the user caches the object accessed by the user; the deletion server is configured to receive a delete request, where the delete request includes an identifier of the object, and the identifier of the object is consistent. Calculating the hash result of the identifier, calculating the hash server according to the hash result, and using the corresponding cache server as the current cache server to determine that the current cache is fast. Whether the server is in an active state and the active time is greater than an expiration time of the object, when it is determined that the current cache server is in an active state and the active time is greater than an expiration time of the object, from the current cache server In order to solve the above technical problem, the embodiment of the present invention further provides a deletion server, which is implemented as follows: The deletion server includes: 201222286 a receiving unit, configured to receive a deletion request, where the deletion request includes an identifier of the object; and a calculating unit, configured to perform a consistent hash calculation on the identifier of the object a hashing result of the identification word; a positioning unit, configured to locate the corresponding cache server according to the hash result, and use the corresponding cache server as the current cache server i determination unit, Determining whether the current cache server is in an active state and the active time is greater than an expiration time of the object; the deleting unit is configured to determine that the current cache server is in an active state and the active time is greater than an expiration of the object At time, the object is deleted from the current cache server. It can be seen that, in the embodiment of the present invention, the deletion request of the identifier containing the object is received, and the hash result is obtained by performing a consistent hash calculation on the identifier of the object, and the corresponding cache server is located according to the hash result. The corresponding cache server is used as the current cache server to determine whether the current cache server is in an active state and the active time is greater than the expiration time of the object. When it is determined that the current cache server is in an active state and the active time is greater than the expiration of the object. At the time, the object is deleted from the current cache server. Therefore, in the embodiment of the present invention, it is not necessary to perform the operation of deleting the object on all the cache servers, but the object to be deleted is accurately located by comparing the active time of the cache server and the expiration time of the object. The cache server performs the delete operation, thereby saving the resources consumed by other cache servers to perform the delete operation, and improving the overall performance of the distributed cache system -8 - 201222286. Embodiments of the present invention provide a method, system, and deletion server for deleting a cached object. The above-mentioned objects, features, and advantages of the embodiments of the present invention will become more apparent and understood. Give further details. The deletion of objects in the distributed cache system in the embodiment of the present invention is based on the objects already stored on the distributed cache server in the system. Therefore, the following concludes a description of how objects in existing systems can be accessed on a decentralized cache server in conjunction with a consistent hash algorithm. In the decentralized cache system, the cache server calculated by the consistent hash algorithm will be arranged on a ring of 0 to 2 3 2 power according to the size of its hash. When calculating the hash of the cache server, the IP address of each cache server is calculated by the selected hash function to obtain a hash, which is a 32-bit integer. The corresponding cache server is mapped to the corresponding position on the ring according to the size of the integer. Referring to Figure 1, an example of a 0 to 2 32-th power ring, assuming that the decentralized cache system includes four cache servers, after the consistency hash calculation, the four cache servers are based on The size of the hash is mapped on the ring as shown in Figure 1, clockwise for the cache server 1, cache server 2, cache server 3 and cache server 4; when the user wants to 201222286 When the decentralized cache server accesses an object (the object can be a network resource such as pictures, audio and video), the object is hashed (usually hashing the identifier URL of the object), and the obtained object will be obtained. Hash 値 as a key 値, according to the size of the key 将 map it to the corresponding position on the ring of 0 to 2 of the 3 2 power, and the position of the key 作为 as the starting position, on the ring The first cache server is found clockwise, and the user accesses the object to be accessed by the first cache server that is found, if the first cache server that is found clockwise is unavailable (for example, 宕Machine), continue to search clockwise until you find one The cache server used. If there is an object on the available cache server that the user wants to access, the object is returned to the user by the dispatch server, and if there is no object to be accessed by the available cache server, the cache is accessed. The server requests the object from the source data server and saves the object on the local machine, and returns the object to the dispatch server, and the dispatch server returns the object to the user. Each object stored on the cache server has an expiration time. When the object's cache time exceeds the expiration time, the cache server will automatically delete the object. Thereafter, when the user accesses the object again through the cache server, the object can be retrieved from the source data server again, and the foregoing process is repeated. 2 is a flowchart of a first embodiment of a method for deleting an object of a decentralized cache according to the present invention. The embodiment only shows an object when the active time of the cached server is greater than the survival time of the object to be deleted. Delete process step 2 0 1 : Receive the delete request, which contains the -10- 201222286 identifier of the object. When a decentralized cache system is applied to a large website, objects refer to network resources such as pictures, audio and video, and each specific network resource is located by a URL (Universal Resource Locator). Step 202: Obtain a hash result 识别 of the recognized word by performing a consistent hash calculation on the identifier of the object. In this step, the process of consistently hashing the identifier of the object to obtain the hash result is consistent with the calculation process performed in the prior art for accessing the object, and details are not described herein. Step 2 0 3: According to the hash result, the corresponding cache server is positioned as the current cache server. Combined with the consistent hash ring shown in Figure 1, it can be known that after the hash of the object's identification word is calculated and the hash result is obtained, the hash result can be mapped as a key to the consistent hash circle. The corresponding position on the ring, and from this position, the first cache server is searched clockwise, since the first cache server found is the cache server scheduled when the user wants to access the object. Therefore, when the first cache server is in an active state, and there is a user accessing the object and the expiration time of the object is not exceeded, the object to be deleted must be cached. Step 204: Determine whether the current cache server is in an active state and the active time is greater than an expiration time of the object. Step 205: When it is determined that the current cache server is in an active state and the active time is greater than the expiration time of the object, the object is deleted from the current cache server -11 - 201222286. Active time refers to the duration of the cache server being active. When the first cache server being located is active and the active time is greater than the expiration time of the object, then since the cache server is currently active, then all Requests to access the object will be sent to the cache server', and even if the object exists on other cache servers, it will be automatically deleted because the existence time exceeds the expiration time of the object. The first cache server can perform the operation of deleting the URL. 3 is a flowchart of a second embodiment of a method for deleting a decentralized cache object according to the present invention. The embodiment shows in detail the process of deleting an object according to the active state and state history information of the cached server: Step 3: 1: Pre-establish the state table of the cache server, and save the time stamp of the last state change of each cache server and the current state of each cache server by the state table. In the embodiment of the present invention, a state table of the cache server is established. Each entry of the state table is used to record the time stamp of the last state change of the cache server and the current state of each cache server. The duration of the current state of the cache server can be determined by a time stamp. The current state can include an active state and an inactive state. The inactive state generally refers to a crash of the cache server. Step 302: Receive a deletion request, where the deletion request includes an identifier of the object. Step 3 0 3: The hash result of the recognized word is obtained by performing a consistent hash calculation on the identifier of the object. -12- 201222286 Step 3 04: According to the hash result, locate the corresponding cache server and use the corresponding cache server as the current cache server. Step 305: Determine whether the current cache server is in an active state. If yes, execute step 306; otherwise, perform step 309. Step 306: Determine whether the active time of the current cache server is greater than the expiration time of the object. If yes, go to step 3 07; otherwise, go to step 3 08. Step 3 07: Delete the object from the current cache server and end the current process. When the current cache server is found to be active according to the status table, and the active time is greater than the expiration time of the object, since the cache server is currently active, all requests for accessing the object are sent to the cache server. On the other cache servers, even if the object exists, it will be automatically deleted because the existence time exceeds the expiration time of the object. At this time, only the operation of deleting the URL needs to be performed on the first cache server that is located. Step 3 0 8: Delete the object from the current cache server, migrate from the current cache server to the next cache server, and use the next cache server as the current cache server. Return to step 305. When it is found according to the state table that the current cache server is in an active state, and it is determined according to the record of its time stamp that its active time is less than the expiration time of the object, the object is first deleted from the cache server; then, considering that The cache server is inactive before the active state, and when the cache server is in an inactive state, the request to access the object to be deleted may be sequentially migrated to the current hash table on the consistent hash ring. The cache server makes the next cache server object, so it is necessary to sequentially acquire the next cache server as the current cache server, and then disconnect, so return to step 3 05. Step 309: Determine the expiration time of the current cache server for the object, and if yes, perform step 3 1 1. Step 3 1 0: From the current cache server sequence server, and the next cache server as the back step 3 0 5 . When the current cache server is found according to the state table, and the non-live expiration time is determined according to the record of its time stamp, the access of the non-live object of the current cache server may be sequentially migrated to the consistency hash server. The next cache server makes it possible to cache the object. Therefore, the sequencer is required, and the next cache server is used as the current state, so return to step 3 0 5 for In the case of a server whose inactive time is greater than the object, when it returns to the active state, the expiration time of the piece, the cache server will perform the operation. Step 3 1 1 : Record the identification word of the object, and the next server of the cache server may also cache the server, and determine whether the next new state is inactive 3 3 0; otherwise Execute the migration to the next cache server before the cache, the inactive state of the device is greater than the hop time of the object, and the current cache is taken on the cached ring. Cache the servo cache server, restart the cache time of the expiration time, and since the physical execution has been performed, the object cache is migrated from the current cache server-14-201222286 to the next cache server, and The next fast cache server, return to step 3 0 5 » When the current cache server is found according to the status table and its idle time expires according to the record of its time stamp, then the current cache is in the current cache. The server's inactive time, except for the access of the object, may be sequentially migrated to the consistency hash ring to fetch the server's next cache server, so that the next device may also cache the object faster, so sequential acquisition is required. Is a 'and the next station as the current cache server cache servo judge its state, returns to step 305. For an expired server whose original inactivity time is less than the object, it is necessary to record the identification of the object to be deleted at the same time. The cache server recovers less than the expiration time of the object, and the object can be deleted according to the recorded identification word. 4 is a schematic diagram of a system structure of an embodiment of a distributed cacher of the present invention: a data server in the system structure, N cache servers (N is a positive integer) server, and a delete proxy server . In the embodiment of the present invention, in order to implement the server for adding the decentralized cached object, the source data server, the cache server, and the data in the existing manner are implemented in the distributed cache system. The scheduling server (also referred to as the load t haproxy ) receives the user's object access request, and according to the server, the inactive state is smaller than the object, and the current cache server is cached. And re-cache the servo word, so that when the active state is deleted, the method includes a source, and a scheduling server removes the consistency of the dispatcher in the dispatching server for the row-distributed server. The 201222286 algorithm schedules a cache server, and the scheduling process is consistent with the foregoing description of the prior art, and details are not described herein again. The cache server (which can be implemented by hosting the open source cache service program Squid on the server) receives the scheduling request of the scheduling server, returns the object to be accessed by the user from the local cache, or obtains from the source data server. And return the object that the user wants to access. The delete proxy is an added server in the system structure of the present invention, and uses the same consistent hash algorithm as the scheduling server to implement deletion of the cached object. The delete proxy server can be a standalone server, or can be integrated into a cache server, and the cache server can perform the delete function at the same time, and the delete proxy server can be connected with all caches in the system. The server communicates. The object deletion request in the system is transmitted to the deletion proxy server. For example, when a malicious image needs to be deleted, or when an item is delisted, its image needs to be deleted. At this time, a deletion request is sent to the deletion proxy server. The deletion request contains the identifier of the object to be deleted (for example, the link address of the malicious picture). At the same time, the delete proxy server also maintains a status table containing status information of all the cache servers. The status table records two pieces of information of each cache server, one piece of information is the last time the cache server occurred. The timestamp of the state change (by which the timestamp can calculate the duration of the last state change of the cache server), and another piece of information is the current state of the cache server, by which the cache server can be determined Active or down. Assuming that the identifier of the object to be deleted is url_a, the deletion process of the embodiment of the present invention is described in conjunction with the one-16-201222286-induced hash ring of FIG. Url_a represents a website resource, usually the link address of the object. When it is determined that the url_a is to be deleted, the object is first deleted on the source data server, and then the Url_a existing on the cache server is deleted. At this point, after performing a consistent hash calculation on url_a, it is determined that the url_a is accessed first to the cache server 1 on the consistency hash ring, and then the status table is searched. The processing flow is as shown in FIG. 5: 501: Receive an object deletion request including uri_a. Step 5 02: Determine the cache server 1 that needs to be scheduled to access the url_a according to the consistency hash calculation. Step 5: Determine whether the currently scheduled cache server is in an active state and its active time is greater than the expiration time of the object url_a. If yes, perform step 5 0 4; otherwise, perform step 5 0 5. Step 504: Delete the object url_a on the currently scheduled cache server, and end the current process. If it is found that the current state of the cache server 1 is "active" and its active time is greater than the expiration time of url_a according to the description of its time stamp, it means that whether the cache server 1 is down, due to the fast If server 1 is currently active, all requests to access url_a will be sent to cache server 1, and even if the object url_a exists on other cache servers, it will be automatically because the existence time exceeds the expiration time of url_a. Delete, at this time only need to perform the operation of deleting the url on the cache server 1. Step 5 0 5: Determine whether the currently scheduled cache server is still in the -17-201222286 down state. If yes, execute step 5 0 6; otherwise, perform step 5 0 8 〇 step 506: determine that the current state is down. Whether the downtime of the cache server exceeds the expiration time of the object url_a, and if so, step 5 09 is performed; otherwise, step 507 is performed. If it is found that the current state of the cache server 1 is "downtime, and it is judged according to the record of its time stamp that the downtime exceeds the expiration time of the object url_a, then the cache server 1 "downtime" time The access to the object url_a may be sequentially migrated to any one of the cache server 2 to the cache server 4, so it is necessary to sequentially acquire the next cache server, and repeat the step from the cache server. 503 starts execution; and for the cache server 1 itself, once it is restored to the active state, since the expiration time of the object url_a has been exceeded, the cache server 1 automatically performs the delete operation on the object url_a. Step 507: Save the current If the cache server and the object url_a are cached, go to step 5 0 9. If the current state of the cache server 1 is found as "downtime, and the timeout is judged according to the timestamp, the downtime is less than the expiration of the object url_a. Time, during the cache server "down" time, access to the object url_a may be sequentially migrated to any of the cache server 2 to the cache server 4 'required The next cache server is acquired, and the cache server is repeatedly executed from step 503: and since the cache duration of the cache server 1 is less than the expiration time of the object url-a, it is necessary to simultaneously record the The url_a ' of the object so that when the cache server 1 is restored to the active state within the expiration time of the object url_a less than -18-201222286, the object url_a can be deleted according to the record, wherein the current cache server 1 and the url_a of the object can be The corresponding relationship is saved in the delayed deletion list. When the cache server 1 resumes the active state within the expiration time of the object url_a, the object url_a on the cache server 1 is deleted according to the entry recorded in the delayed deletion list. . Step 5 08: Delete the object url_a on the current cache server. If it is found that the current state of the cache server 1 is "active" and it is judged according to the record of its time stamp that its active time is less than the expiration time of url_a, the url_a is first deleted from the cache server 1; The cache server 1 is in the "down" state before the "active" state. When the cache server 1 is in the "down" state, the request to access the url_a may be sequentially migrated to the cache server 2 to the cache server. Any one of 4, so it is necessary to sequentially acquire the next cache server, and repeat the execution of the cache server from step 503. Step 5: 9: Determine whether the current cache server can be mapped to the next cache server. If yes, execute step 5 1 0; otherwise, end the current process. Step 5: 0: The sequence is mapped from the current cache server to the next cache server, and the process returns to step 503. It can be seen that, in the embodiment of the present invention, the deletion proxy server maintains the same consistent hash algorithm as the scheduling server, by combining the state change information of the cache server with the cache server where the object to be deleted is located. Precise positioning 'Because it can delete objects accurately and comprehensively, without having to delete all the servers from the fast -19-201222286, it reduces the deletion of all fast-access servers in the system compared with the prior art. The system resources used. The following describes the implementation process of the embodiment of the present invention by deleting the malicious image in the decentralized cache picture system as follows: Assume that the distributed cache system includes three cache servers, respectively S 1 . S 2 and S 3, each cache server identifies with its IP address as an identifier, and the hash addresses of SI, S2, and S3 are respectively hashed by the selected hash function hash_fuction_x, assuming that The hash is three integers, which are 1, 、, 2000, and 3 000 ' respectively. The mapping positions of the three cache servers on the ring are as shown in FIG. 3A, and the three cache servos are assumed. The state table of the initial time is shown in Table 1, where Last_stamp represents the timestamp of the last time the cache server changed state, Currentjtatus represents the current state of the cache server: Table 1 Server SI S2 S3 Last stamp 0 0 0 Current status Up Up Up In the above table 1, the Last_stamp of SI, S2 and S3 at the initial time is "0", indicating that the time stamps of the initial time S1, S2 and S3 are all 〇, and the time stamp can be "day" Unit Record, for example, the initial boot is the first day, the timestamp is "", and the subsequent timestamps are incremented by 1 for each subsequent day; Current_status is "UP" ' indicates that Si • 20 - 201222286 , S2 and S3 are at the initial moment Both are active. When Current_status is "DOWN", it indicates that it is in the state of failure. Assume that at time 1, the user wants to access the object resource url_l, and after the url_l is calculated by the hash function hash_fuction_x, the obtained hash 値 is 2 5 3, and the hash 値 is mapped to the ring shown in FIG. 3A. Above, the first cache server that is clockwise found from the position of the hash map is S1, so the request to access the object resource url_1 is processed by S1, assuming that the user first uses S1 accesses url_l, then S1 obtains the object resource url_l from the source server, saves the url_l and returns the url_l to the client. Suppose that at time 2, S 1 is down, the status table of the cache server is updated at this time, as shown in Table 2 below:
伺服器 SI S2 S3 Last stamp 2 0 0 Current status DOWN Up Up 上表 2 中,S1 的 Current_status 爲 “DOWN” ’表 示S 1最近一次發生狀態變化後的狀態爲“宕機” ’即S 1 當前處於“宕機”狀態’ Last_stamp從“ 〇”變爲‘‘ 2” ’ 表示S1變化爲“宕機”狀態的時間戳記爲“ 2” ’則S 1 處於“宕機”狀態的持續時間爲當前時刻的時間戳記與該 時間戳記“ 2”的差値。 假設在時刻3,用戶再次想要訪問物件資源url_ 1 ’ -21 - 201222286 則對該url_l藉由哈希函數hash_fuction_x計算後,得到 的哈希値爲2 5 3,從圓環上哈希値2 5 3映射的位置開始順 時針查找到的第一個快取伺服器爲S 1,此時藉由狀態表 表2查找到S 1宕機,因此從S 1開始在圓環上順時針查找 到下一個快取伺服器爲S2,此時S2處於活躍狀態,因此 訪問物件資源url_l的請求由S2進行處理,此時S1和S2 上都快取了物件資源url_l。 假設在時刻4,監測到物件資源url_ 1爲惡意圖片, 則需要將該url_l從分散式快取系統中刪除,此時可以由 系統維護人員藉由HTTP的標準 post方法向刪除代理伺 服器發送一條刪除請求,該刪除請求中包含的刪除目標爲 ur1_ 1 〇 刪除代理伺服器接收到刪除請求後,讀取其中的刪除 目標url_l,並藉由哈希函數hash_fuction_x計算url_l 的哈希値爲253,此時將哈希値253映射到圖3A所示的 圓環上,從哈希値253映射的位置開始順時針査找到的第 —個快取伺服器爲S1,此時進一步査找狀態表可知S1從 時刻2開始持續處於宕機狀態,因此儲存在S1上的url_l 無法立刻刪除,將S 1和對應的url_l添加到延遲刪除列 表中,待S1恢復後再進行刪除;然後在圓環上從S 1開始 .順時針查找到S2,進一步查找狀態表可知S2此時處於活 躍狀態,因此將刪除請求發送給S2,由S2根據刪除請求 査找到其上快取的惡意圖片url_l並刪除,由於S2在歷 史時刻未宕機過,因此刪除操作結束。 -22- 201222286 與本發明分散式快取的物件刪除方法的實施例相對應 ’本發明還提供了分散式快取的物件刪除系統及刪除伺服 器的實施例。 參見圖7,爲本發明分散式快取的物件刪除系統的實 施例區塊圖: 該系統包括:若干快取伺服器7 1 0和刪除伺服器7 2 0 〇 其中’所述若干快取伺服器7 1 0,用戶快取用戶訪問 的物件; 所述刪除伺服器720,用於接收刪除請求,所述刪除 請求中包含物件的識別字,藉由對所述物件的識別字進行 一致性哈希計算得到所述識別字的哈希結果値,根據所述 哈希結果値定位到對應的快取伺服器,將所述對應的快取 伺服器作爲當前快取伺服器,判斷所述當前快取伺服器是 否處於活躍狀態且活躍時間大於所述物件的過期時間,當 判斷當前快取伺服器處於活躍狀態且所述活躍時間大於所 述物件的過期時間時,從所述當前快取伺服器上刪除所述 物件。 進一步,所述刪除伺服器,還用於當判斷所述活躍時 間小於所述過期時間時,從所述當前快取伺服器上刪除所 述物件’從所述當前快取伺服器順序遷移到下一台快取伺 服器’並將所述下一台快取伺服器作爲當前快取伺服器, 返回執行所述判斷當前快取伺服器是否處於活躍狀態且活 躍時間大於所述物件的過期時間的功能; -23- 201222286 所述删除伺服器,還用於當所述當前快取伺服器處於 非活躍狀態時,判斷所述當前快取伺服器的非活躍時間是 否大於所述物件的過期時間,當所述非活躍時間大於所述 過期時間時,從所述當前快取伺服器順序遷移到下一台快 取伺服器,並將所述下一台快取伺服器作爲當前快取伺服 器,返回執行所述判斷當前快取伺服器是否處於活躍狀態 且活躍時間大於所述物件的過期時間的功能; 所述刪除伺服器,還用於當所述非活躍時間不大於所 述過期時間時,記錄所述識別字,並執行從所述當前快取 伺服器順序遷移到下一台快取伺服器的功能,以及當所述 當前快取伺服器進入活躍狀態後,根據所述記錄的識別字 刪除所述物件; 所述刪除伺服器,還用於預先建立快取伺服器的狀態 表,藉由所述狀態表保存每一個快取伺服器最後一次發生 狀態變化時的時間戳記,以及每一個快取伺服器的當前狀 態,其中所述時間戳記用於判斷所述快取伺服器的當前狀 態的持續時間。 參見圖8,爲本發明刪除伺服器的第一實施例區塊圖 該刪除伺服器包括:接收單元810、計算單元820、 定位單元8 3 0、判斷單元840和刪除單元8 5 0。 其中,接收單元810,用於接收删除請求,所述刪除 請求中包含物件的識別字; 計算單元820,用於藉由對所述物件的識別字進行一 •24- 201222286 致性哈希計算得到所述識別字的哈希結果値; 疋位單兀8 3 0 ’用於根據所述哈希結果値定位到對應 的快取伺服器’將所述對應的快取伺服器作爲當前快取伺 服器; 判斷單元840’用於判斷所述當前快取伺服器是否處 於活躍狀態且活躍時間大於所述物件的過期時間; 删除單元8 5 0 ’用於當判斷當前快取伺服器處於活躍 狀態且所述活躍時間大於所述物件的過期時間時,從所述 當前快取伺服器上刪除所述物件。 參見圖9,爲本發明删除伺服器的第二實施例區塊圖 該刪除伺服器包括:建立單元910、保存單元920、 接收單元930、計算單元940、定位單元950、判斷單元 960、刪除單元970、遷移單元980和記錄單元990。 其中,建立單元910,用於預先建立快取伺服器的狀 態表; 保存單元920,用於藉由所述狀態表保存每一個快取 伺服器最後一次發生狀態變化時的時間戳記,以及每一個 快取伺服器的當前狀態,其中所述時間戳記用於判斷所述 快取伺服器的當前狀態的持續時間; 接收單元930,用於接收刪除請求,所述刪除請求中 包含物件的識別字; 計算單元940,用於藉由對所述物件的識別字進行— 致性哈希計算得到所述識別字的哈希結果値; -25- 201222286 定位單元95 0,用於根據所述哈希結果値定位到對應 的快取伺服器,將所述對應的快取伺服器作爲當前快取伺 服器; 判斷單元960,用於判斷所述當前快取伺服器是否處 於活躍狀態且活躍時間大於所述物件的過期時間; 刪除單元970,用於當判斷當前快取伺服器處於活躍 狀態且所述活躍時間大於所述物件的過期時間時,從所述 當前快取伺服器上刪除所述物件; 所述刪除單元970,還用於當判斷所述活躍時間小於 所述過期時間時,從所述當前快取伺服器上刪除所述物件 ;遷移單元9 80,用於從所述當前快取伺服器順序遷移到 下一台快取伺服器,並將所述下一台快取伺服器作爲當前 快取伺服器,並觸發所述判斷單元960 ; 所述判斷單元970,還用於當所述當前快取伺服器處 於非活躍狀態時,判斷所述當前快取伺服器的非活躍時間 是否大於所述物件的過期時間;所述遷移單元980,還用 於當所述非活躍時間大於所述過期時間時,從所述當前快 取伺服器順序遷移到下一台快取伺服器,並將所述下一台 快取伺服器作爲當前快取伺服器,並觸發所述判斷單元 960 ; 記錄單元990,用於當所述非活躍時間不大於所述過 期時間時,記錄所述識別字,並觸發所述遷移單元980 ; 所述刪除單元970,還用於當所述當前快取伺服器進 入活躍狀態後,根據所述記錄的識別字刪除所述物件》 -26- 201222286 藉由以上的實施方式的描述可知,本發明實施例中接 收包含物件的識別字的刪除請求,藉由對物件的識別字進 行一致性哈希計算得到哈希結果値,根據哈希結果値定位 到對應的快取伺服器,將對應的快取伺服器作爲當前快取 伺服器,判斷當前快取伺服器是否處於活躍狀態且活躍時 間大於物件的過期時間,當判斷當前快取伺服器處於活躍 狀態且活躍時間大於物件的過期時間時,從當前快取伺服 器上刪除所述物件。由此可知,本發明實施例中無需在所 有快取伺服器上執行刪除物件的操作,而是藉由比較所定 位快取伺服器的活躍時間和物件的過期時間,精確定位到 包含待刪除物件的快取伺服器,並執行刪除操作,由此節 約了其他快取伺服器爲執行刪除操作所要耗費的資源,提 高了分散式快取系統的整體性能。 藉由以上的實施方式的描述可知,本領域的技術人員 可以清楚地瞭解到本發明可借助軟體加必需的通用硬體平 臺的方式來實現。基於這樣的理解,本發明的技術方案本 質上或者說對現有技術做出貢獻的部分可以以軟體產品的 形式體現出來,該電腦軟體產品可以儲存在儲存媒體中, 如ROM/RAM、磁碟、光碟等,包括若干指令用以使得一 台電腦設備(可以是個人電腦’伺服器,或者網路設備等 )執行本發明各個實施例或者實施例的某些部分所述的方 法。 本說明書中的各個實施例均採用遞進的方式描述,各 個實施例之間相同相似的部分互相參見即可,每個實施例 -27- 201222286 重點說明的都是與其他實施例的不同之處。尤其,對於系 統實施例而言,由於其基本相似於方法實施例,所以描述 的比較簡單,相關之處參見方法實施例的部分說明即可。 本發明可用於眾多通用或專用的計算系統環境或配置 中。例如:個人電腦、伺服器電腦、手持設備或可攜式設 備、平板型設備、多處理器系統、基於微處理器的系統、 機上盒、可編程的消費電子設備、網路PC、小型電腦、 大型電腦、包括以上任何系統或設備的分散式計算環境等 等。 本發明可以在由電腦執行的電腦可執行指令的一般上 下文中描述,例如程式模組。一般地,程式模組包括執行 特定任務或實現特定抽象資料類型的常式、程式、物件、 元件、資料結構等等。也可以在分散式計算環境中實踐本 發明’在這些分散式計算環境中,由藉由通信網路而被連 接的遠端處理設備來執行任務。在分散式計算環境中,程 式模組可以位於包括儲存設備在內的本地和遠端電腦儲存 媒體中。 雖然藉由實施例描繪了本發明,本領域普通技術人員 知道’本發明有許多變形和變化而不脫離本發明的精神, 希望所附的申請專利範圍包括這些變形和變化而不脫離本 發明的精神。 【圖式簡單說明】 爲了更清楚地說明本發明實施例或現有技術中的技術 -28- 201222286 方案,下面將對實施例或現有技術描述中所需要使用的附 圖作簡單地介紹,顯而易見地,下面描述中的附圖僅僅是 本發明中記載的一些實施例’對於本領域普通技術人貝來 講,在不付出創造性勞動性的前提下,還可以根據這些附 圖獲得其他的附圖。 圖1爲本發明實施例中一致性哈希圓環的示意圖; 圖2爲本發明分散式快取的物件删除方法的第一實施 例流程圖; 圖3爲本發明分散式快取的物件刪除方法的第二實施 例流程圖; 圖4爲應用本發明分散式快取的物件刪除方法實施例 的一種系統結構示意圖; 圖5爲應用圖4中的系統結構執行物件刪除的流程; 圖6爲本發明應用實例中的一致性哈希圓環示意圖; 圖7爲本發明分散式快取的物件刪除系統的實施例區 塊圖; 圖8爲本發明删除伺服器的第—實施例區塊圖; 圖9爲本發明刪除伺服器的第二實施例區塊圖。 【主要元件符號說明】 1 :快取伺服器 2:快取伺服器 3 :快取伺服器 4:快取伺服器 -29- 201222286 7 1 0 :快取伺服器 720 :刪除伺服器 810 :接收單元 820 :計算單元 8 3 0 :定位單元 840 :判斷單元 8 5 0 :刪除單元 9 1 0 :建立單元 920 :保存單元 93 0 :接收單元 940 :計算單元 9 5 0 :定位單元 960 :判斷單元 9 7 0 :刪除單元 98 0 :遷移單元 990 :記錄單元Server SI S2 S3 Last stamp 2 0 0 Current status DOWN Up Up In Table 2, the Current_status of S1 is “DOWN”. 'The status of the last state change after S 1 is “down”. That is, S 1 is currently in "Down" status ' Last_stamp changed from '〇' to '' 2'' The timestamp indicating that S1 changes to "down" status is "2" 'The duration of S 1 in the "down" state is the current time The timestamp is the difference from the timestamp "2". Suppose at time 3, the user wants to access the object resource url_ 1 ' -21 - 201222286 again. Then the url_l is calculated by the hash function hash_fuction_x.値 is 2 5 3, the first cache server that is clockwise found from the position of the hash on the ring is 5, and the S1 is found by the state table 2 Therefore, starting from S1, the next cache server is clockwise to find S2. At this time, S2 is in an active state, so the request for accessing the object resource url_l is processed by S2, and both S1 and S2 are fast. Take the object resource url_l. At time 4, if the object resource url_1 is detected as a malicious picture, the url_l needs to be deleted from the distributed cache system. At this time, the system maintenance personnel can send a deletion to the delete proxy server by using the standard post method of HTTP. Request, the delete target included in the delete request is ur1_ 1 〇 After the delete proxy server receives the delete request, it reads the delete target url_l, and calculates the hash url of url_l by the hash function hash_fuction_x to 253. The hash 253 is mapped to the ring shown in FIG. 3A, and the first cache server that is clockwise searched from the position mapped by the hash 253 is S1. At this time, the state table is further searched for the S1 slave time. 2 starts to be in the down state, so the url_l stored on S1 cannot be deleted immediately, and S 1 and the corresponding url_l are added to the deferred deletion list, and then deleted after S1 is restored; then, starting from S 1 on the ring Looking up S2 clockwise, further look up the status table to know that S2 is active at this time, so send the delete request to S2, and find it on S2 according to the delete request. The malicious picture url_l is deleted, and since the S2 has not crashed at the historical moment, the deletion operation ends. -22- 201222286 Corresponding to the embodiment of the decentralized cache object deletion method of the present invention, the present invention also provides a decentralized An embodiment of the cached object deletion system and the deletion server. Referring to FIG. 7, a block diagram of an embodiment of the distributed cached object deletion system of the present invention: the system includes: a plurality of cache servers 7 1 0 and delete The server 7 2 0 〇 wherein the plurality of cache servers 7 1 0, the user caches the object accessed by the user; the deletion server 720 is configured to receive a delete request, where the delete request includes the identifier of the object Obtaining a hash result of the recognized word by performing a consistent hash calculation on the identifier of the object, and positioning the corresponding cache server according to the hash result, and the corresponding cache is obtained. The server acts as the current cache server, determines whether the current cache server is in an active state, and the active time is greater than the expiration time of the object, when determining the current cache server When the active state and the active time is greater than the expiration time of said object, remove the article from the current cache server. Further, the deleting server is further configured to: when the active time is less than the expiration time, delete the object from the current cache server to migrate from the current cache server to the next a cache server's and the next cache server as the current cache server, returning to perform the determination of whether the current cache server is active and the active time is greater than the expiration time of the object. The function of the deletion server is also used to determine whether the current cache time of the current cache server is greater than the expiration time of the object when the current cache server is in an inactive state. When the inactivity time is greater than the expiration time, the current cache server is sequentially migrated to the next cache server, and the next cache server is used as the current cache server. Returning to the function of determining whether the current cache server is in an active state and the active time is greater than an expiration time of the object; the deleting server is further configured to be used as the non- Recording the identification word when the active time is not greater than the expiration time, and performing a function of sequentially migrating from the current cache server to the next cache server, and when the current cache server enters active After the state, deleting the object according to the recorded identification word; the deleting server is further configured to pre-establish a state table of the cache server, and the last time the cache server is saved by the state table A timestamp when the state changes, and the current state of each cache server, wherein the timestamp is used to determine the duration of the current state of the cache server. Referring to FIG. 8, a block diagram of a first embodiment of a deletion server according to the present invention includes: a receiving unit 810, a calculating unit 820, a positioning unit 803, a determining unit 840, and a deleting unit 850. The receiving unit 810 is configured to receive a deletion request, where the deletion request includes an identifier of the object, and the calculating unit 820 is configured to perform a hysteretic hash calculation on the identifier of the object by using a 24-24 201222286 a hash result of the identification word 疋; a unit 兀 8 3 0 ' is used to locate the corresponding cache server according to the hash result ' 'the corresponding cache server as the current cache server The determining unit 840' is configured to determine whether the current cache server is in an active state and the active time is greater than an expiration time of the object; the deleting unit 850 ' is used to determine that the current cache server is active and When the active time is greater than the expiration time of the object, the object is deleted from the current cache server. Referring to FIG. 9, a block diagram of a second embodiment of the deletion server of the present invention includes: an establishing unit 910, a saving unit 920, a receiving unit 930, a calculating unit 940, a positioning unit 950, a determining unit 960, and a deleting unit. 970, migration unit 980, and recording unit 990. The establishing unit 910 is configured to pre-establish a state table of the cache server, and the saving unit 920 is configured to save, by using the state table, a time stamp when each of the cache servers changes state last time, and each time The current state of the cache server, wherein the timestamp is used to determine the duration of the current state of the cache server; the receiving unit 930 is configured to receive a delete request, where the delete request includes an identifier of the object; The calculating unit 940 is configured to obtain a hash result of the identifier by performing a hash calculation on the identifier of the object; -25- 201222286 positioning unit 95 0, according to the hash result値 locating to the corresponding cache server, the corresponding cache server is used as the current cache server; the determining unit 960 is configured to determine whether the current cache server is in an active state and the active time is greater than the The expiration time of the object; the deleting unit 970, configured to: when determining that the current cache server is in an active state, and the active time is greater than an expiration time of the object Deleting the object from the current cache server; the deleting unit 970 is further configured to delete the object from the current cache server when determining that the active time is less than the expiration time a migration unit 980, configured to sequentially migrate from the current cache server to a next cache server, and use the next cache server as a current cache server, and trigger the determination The unit 960 is further configured to: determine, when the current cache server is in an inactive state, whether the inactivity time of the current cache server is greater than an expiration time of the object; The unit 980 is further configured to: when the inactivity time is greater than the expiration time, sequentially migrate from the current cache server to a next cache server, and use the next cache server as The current cache server triggers the judging unit 960; the recording unit 990 is configured to record the identification word when the inactivity time is not greater than the expiration time, and trigger the migration unit 980; delete The unit 970 is further configured to: after the current cache server enters an active state, delete the object according to the recorded identification word. -26-201222286, as described in the foregoing embodiments, in the embodiment of the present invention, Receiving a deletion request including the identification word of the object, obtaining a hash result by performing a consistent hash calculation on the identification word of the object, and positioning the corresponding cache server according to the hash result, corresponding to the cache server As the current cache server, it is determined whether the current cache server is in an active state and the active time is greater than the expiration time of the object. When it is determined that the current cache server is in an active state and the active time is greater than the expiration time of the object, the current cache is obtained from the current cache. The object is deleted on the server. Therefore, in the embodiment of the present invention, it is not necessary to perform the operation of deleting the object on all the cache servers, but the object to be deleted is accurately located by comparing the active time of the cache server and the expiration time of the object. The cache server performs the delete operation, thereby saving the resources that other cache servers spend to perform the delete operation, and improving the overall performance of the distributed cache system. From the description of the above embodiments, it will be apparent to those skilled in the art that the present invention can be implemented by means of a software plus a necessary universal hardware platform. Based on such understanding, the technical solution of the present invention can be embodied in the form of a software product in essence or in the form of a software product, which can be stored in a storage medium such as a ROM/RAM or a disk. Optical disks, etc., include instructions for causing a computer device (which may be a personal computer 'server, or network device, etc.) to perform the methods described in various embodiments of the present invention or portions of the embodiments. The various embodiments in the present specification are described in a progressive manner, and the same similar parts between the various embodiments may be referred to each other, and each embodiment -27-201222286 focuses on the differences from other embodiments. . In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment. The invention is applicable to a wide variety of general purpose or special purpose computing system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, small computers , large computers, decentralized computing environments including any of the above systems or devices, and so on. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as a program module. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The present invention can also be practiced in a distributed computing environment where tasks are performed by remote processing devices that are connected by a communication network. In a distributed computing environment, the program modules can be located in local and remote computer storage media, including storage devices. Although the present invention has been described by way of example, it is understood by those of ordinary skill in the art spirit. BRIEF DESCRIPTION OF THE DRAWINGS In order to more clearly illustrate the embodiment of the present invention or the prior art technique -28-201222286, the drawings used in the embodiments or the prior art description will be briefly described below, obviously The drawings in the following description are only some of the embodiments described in the present invention. For those skilled in the art, other drawings may be obtained from these drawings without any inventive labor. 1 is a schematic diagram of a consistent hash ring according to an embodiment of the present invention; FIG. 2 is a flowchart of a first embodiment of a method for deleting a decentralized cache object according to the present invention; FIG. 4 is a schematic diagram of a system structure of an embodiment of an object deletion method using the distributed cache of the present invention; FIG. 5 is a flowchart of executing the object deletion by using the system structure in FIG. 4; FIG. 7 is a block diagram of an embodiment of a decentralized cached object deletion system according to the present invention; FIG. 8 is a block diagram of a first embodiment of the deletion server of the present invention; FIG. 9 is a block diagram of a second embodiment of the deletion server of the present invention. [Main component symbol description] 1 : Cache server 2: Cache server 3 : Cache server 4 : Cache server -29 - 201222286 7 1 0 : Cache server 720 : Delete server 810 : Receive Unit 820: Calculation unit 8 3 0 : Positioning unit 840 : Judging unit 8 5 0 : Deleting unit 9 1 0 : Setting unit 920 : Saving unit 93 0 : Receiving unit 940 : Computation unit 9 5 0 : Positioning unit 960 : Judging unit 9 7 0 : deletion unit 98 0 : migration unit 990 : recording unit