开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 2511|回复: 3
收起左侧

[其它] 如何清除高速缓存时应用程序主机 web 浏览器控件

[复制链接]

结帖率:67% (16/24)
发表于 2011-7-25 03:29:08 | 显示全部楼层 |阅读模式   广东省广州市
本帖最后由 微凉 于 2011-7-25 03:30 编辑

当您的应用程序承载 web 浏览器控件时,可能需要以编程方式清除缓存。此功能不能通过 web 浏览器控件的接口。本文介绍了如何使用 WinInet API 函数直接清除缓存。
使用 WinInet API FindFirstURLCacheEntry 查找第一个缓存项,并使用 FindNextUrlCacheEntry 枚举通过缓存。若要删除的每个条目使用 DeleteUrlCacheEntry。

请注意在下面的示例中使用 FindFirstUrlCacheGroup、 FindNextUrlCacheGroup 和 DeleteUrlCacheGroup。因此若要防止出现错误需要正确的检查,如图所示,这些 API 函数仅有成为可用的 Internet Explorer 5。

以下步骤显示如何在 Visual Basic 中使用 WinInet API,以清除高速缓存中的所有文件。


  • 创建一个新的 Visual Basic 标准 EXE 项目。
  • 创建在 form1 下的一个命令按钮。
  • 将以下代码粘贴到 form1 的模块中:
Option Explicit

Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _
    ByVal dwFlags As Long, _
    ByVal dwFilter As Long, _
    ByRef lpSearchCondition As Long, _
    ByVal dwSearchCondition As Long, _
    ByRef lpGroupId As Date, _
    ByRef lpReserved As Long) As Long

Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" ( _
    ByVal hFind As Long, _
    ByRef lpGroupId As Date, _
    ByRef lpReserved As Long) As Long
   
Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _
    ByVal sGroupID As Date, _
    ByVal dwFlags As Long, _
    ByRef lpReserved As Long) As Long
   
Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll" Alias "FindFirstUrlCacheEntryA" ( _
    ByVal lpszUrlSearchPattern As String, _
    ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
    ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long
   
Private Type INTERNET_CACHE_ENTRY_INFO
    dwStructSize As Long
    szRestOfData(1024) As Long
End Type

Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" ( _
    ByVal lpszUrlName As Long) As Long

Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll" Alias "FindNextUrlCacheEntryA" ( _
    ByVal hEnumHandle As Long, _
    ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
    ByRef lpdwNextCacheEntryInfoBufferSize As Long) As Long

Private Const CACHGROUP_SEARCH_ALL = &H0
Private Const ERROR_NO_MORE_FILES = 18
Private Const ERROR_NO_MORE_ITEMS = 259
Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE = &H2
Private Const BUFFERSIZE = 2048

Private Sub Command1_Click()
    Dim sGroupID As Date
    Dim hGroup As Long
    Dim hFile As Long
    Dim sEntryInfo As INTERNET_CACHE_ENTRY_INFO
    Dim iSize As Long
        
    On Error Resume Next
   
    ' Delete the groups
    hGroup = FindFirstUrlCacheGroup(0, 0, 0, 0, sGroupID, 0)
   
    ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
    If Err.Number <> 453 Then
        If (hGroup = 0) And (Err.LastDllError <> 2) Then
            MsgBox "An error occurred enumerating the cache groups" & Err.LastDllError
            Exit Sub
        End If
    Else
        Err.Clear
    End If
   
    If (hGroup <> 0) Then
        'we succeeded in finding the first cache group.. enumerate and
        'delete
        Do
            If (0 = DeleteUrlCacheGroup(sGroupID, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, 0)) Then
               
               ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
               If Err.Number <> 453 Then
                 MsgBox "Error deleting cache group " & Err.LastDllError
                 Exit Sub
               Else
                  Err.Clear
               End If
            End If
            iSize = BUFFERSIZE
            If (0 = FindNextUrlCacheGroup(hGroup, sGroupID, iSize)) And (Err.LastDllError <> 2) Then
                MsgBox "Error finding next url cache group! - " & Err.LastDllError
            End If
        Loop Until Err.LastDllError = 2
    End If
  
  ' Delete the files
    sEntryInfo.dwStructSize = 80
    iSize = BUFFERSIZE
    hFile = FindFirstUrlCacheEntry(0, sEntryInfo, iSize)
    If (hFile = 0) Then
        If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then
            GoTo done
        End If
        MsgBox "ERROR: FindFirstUrlCacheEntry - " & Err.LastDllError
        Exit Sub
    End If
    Do
        If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData(0))) _
            And (Err.LastDllError <> 2) Then
            Err.Clear
        End If
        iSize = BUFFERSIZE
        If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize)) And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then
            MsgBox "Error:  Unable to find the next cache entry - " & Err.LastDllError
            Exit Sub
        End If
    Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS
done:
    MsgBox "cache cleared"
    Command1.Enabled = True
End Sub

4.运行您的项目,然后单击 Command1。在您的计算机中高速缓存将被清除。



结帖率:38% (5/13)

签到天数: 1 天

发表于 2012-1-8 16:31:50 | 显示全部楼层   湖北省武汉市
哦   不是蛮懂
回复 支持 反对

使用道具 举报

结帖率:0% (0/1)
发表于 2012-1-11 19:20:40 | 显示全部楼层   湖南省岳阳市
学习学习学习
回复 支持 反对

使用道具 举报

发表于 2012-11-28 19:18:34 | 显示全部楼层   安徽省马鞍山市

学习学习学习
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表