Как очистить кэш 1С?

54884150.png-1600Бывают случаи, когда на данном компьютере пользователя в рабочей базе была старая конфигурация, хотя на любом другом ПК и на сервере она обновилась. Так же может возникать ошибка потока данных. В этих и некоторых других случаях поможет очистка кеша.

В связи с тем, что 1С может быть установлена на различных операционных системах, папка, где хранится кэш, может быть различной.

Для Win XP:

%userprofile%Local SettingsApplication Data1C1Cv82

%userprofile%Application Data1C1Cv82

Для Win 7:
%userprofile%AppDataRoaming1C1Cv82
%userprofile%AppDataLocal1C1Cv82

Серверные оси Windows 2008
C:Users<username>AppDataLocal1C
C:Users<username>AppDataRoaming1C

А самый простой способ найти папки – это использовать поиск по системе(win + F) по ключевым словам «1сv81» и/или «1cv82». Нужные нам папки находятся в каталоге пользователя.

Напимер:

C:Documents and Settings%userprofile%Local SettingsApplication Data1C1Cv81
C:Documents and Settings%userprofile% Local SettingsApplication Data1C1Cv82
C:Documents and Settings%userprofile% Application Data1C1Cv81
C:Documents and Settings%userprofile% Application Data1C1Cv82

Важно:

  1. Кэш хранится в двух папках. Чаще всего эти папки называются «LocalSettings» и «ApplicationData». Обе папки находятся в каталоге пользователя.
  2. Формат кэш-файлов выглядит вот так: «0df525c2-1c3e-44be-b852-c7059f17c5aa» или «0f2c4d8f-cc84-4033-8744-1acfa6204474». Удалять необходимо только те папки, у которых такой же формат в названии.
  3. Не удаляйте файл ibases.v8i — он содержит список баз

Можно ли изменить путь кэша метаданных?
Можно. С помощью групповых политик (gpedit.msc) можно переопределить путь профиля пользователя целиком (не только кэш метаданных).


ВАРИАНТЫ АВТОМАТИЗАЦИИ:

1. Доп. ключик командной строки /ClearCache — очистка кэша клиент-серверных вызовов (используется для тонкого и толстого клиентов в режиме 1С:Предприятия).
title

2. bat / cmd файл:

Код VBS
<code class="vbs" style="color: blue;"> @<span class="keyword" style="font-weight: bold; color: red;">FOR</span> /D %%i <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"C:Users*"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> ( 
@<span class="keyword" style="font-weight: bold; color: red;">FOR</span> /D %%j <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"%%iLocal settingsApplication data1C1Cv82????????-????-????-????-????????????"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> rd /s /q <span class="string" style="color: black;">"%%j"</span> 
@<span class="keyword" style="font-weight: bold; color: red;">FOR</span> /D %%j <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"%%iAppDataRoaming1C1Cv82????????-????-????-????-????????????"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> rd /s /q <span class="string" style="color: black;">"%%j"</span> 
)   </code>

и текст батника с проверкой на ХР или 7:

Код VBS
<code class="vbs" style="color: blue;"> <span class="keyword" style="font-weight: bold; color: red;">If</span> Exist %USERPROFILE%AppDataRoaming<span class="number" style="color: black;">1</span>C<span class="number" style="color: black;">1</span>Cv82 ( 
<span class="keyword" style="font-weight: bold; color: red;">rem</span> Удаляем все файлы в <span class="number" style="color: black;">7</span> 
Del /F /Q %USERPROFILE%AppDataRoaming<span class="number" style="color: black;">1</span>C<span class="number" style="color: black;">1</span>Cv82*.* 
Del /F /Q %USERPROFILE%AppDataLocal<span class="number" style="color: black;">1</span>C<span class="number" style="color: black;">1</span>Cv82*.* 

<span class="keyword" style="font-weight: bold; color: red;">rem</span> Удаляем все каталоги в <span class="number" style="color: black;">7</span> 
<span class="keyword" style="font-weight: bold; color: red;">for</span> /d %%i <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"%USERPROFILE%AppDataRoaming1C1Cv82*"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> rmdir /s /q <span class="string" style="color: black;">"%%i"</span> 
<span class="keyword" style="font-weight: bold; color: red;">for</span> /d %%i <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"%USERPROFILE%AppDataLocal1C1Cv82*"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> rmdir /s /q <span class="string" style="color: black;">"%%i"</span> 
) 

<span class="keyword" style="font-weight: bold; color: red;">If</span> Exist %USERPROFILE%Local SettingsApplication Data<span class="number" style="color: black;">1</span>C<span class="number" style="color: black;">1</span>Cv82 ( 
<span class="keyword" style="font-weight: bold; color: red;">rem</span> Удаляем все файлы в XP 
Del /F /Q %USERPROFILE%Local SettingsApplication Data<span class="number" style="color: black;">1</span>C<span class="number" style="color: black;">1</span>Cv82*.* 
Del /F /Q %USERPROFILE%Application Data<span class="number" style="color: black;">1</span>C<span class="number" style="color: black;">1</span>Cv82*.* 

<span class="keyword" style="font-weight: bold; color: red;">rem</span> Удаляем все файлы в XP 
<span class="keyword" style="font-weight: bold; color: red;">for</span> /d %%i <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"%USERPROFILE%Local SettingsApplication Data1C1Cv82*"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> rmdir /s /q <span class="string" style="color: black;">"%%i"</span> 
<span class="keyword" style="font-weight: bold; color: red;">for</span> /d %%i <span class="keyword" style="font-weight: bold; color: red;">in</span> (<span class="string" style="color: black;">"%USERPROFILE%Application Data1C1Cv82*"</span>) <span class="keyword" style="font-weight: bold; color: red;">do</span> rmdir /s /q <span class="string" style="color: black;">"%%i"</span> 
)   </code>

3. Процедуру ОчиститьКэшИПерезапуститьПрограмму() создаем в глобальном модуле и вызываем ее когда нужно почистить кэш 1С

Код 1C v 8.х
<code class="1c8" style="color: blue;"> <span class="comment" style="color: green;">// Процедура создает и запускает vbs файл, который производит очистку кэша.</span>
<span class="comment" style="color: green;">// 1С и презапускает программу</span>
<span class="comment" style="color: green;">//</span>
<span class="function"><span class="keyword" style="font-weight: bold; color: red;">Процедура</span><span class="tail"> ОчиститьКэшИПерезапуститьПрограмму<span class="params">()</span> <span class="export"><span class="keyword" style="font-weight: bold; color: red;">Экспорт</span></span></span></span>

     СкриптФайл <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="keyword" style="font-weight: bold; color: red;">Новый</span> ТекстовыйДокумент<span class="operator" style="font-weight: bold; color: red;">;</span>

     СтрокаСоединенияСБД <span class="operator" style="font-weight: bold; color: red;">=</span> СтрокаСоединенияИнформационнойБазы<span class="operator" style="font-weight: bold; color: red;">(</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     СтрокаЗапускаПрограммы <span class="operator" style="font-weight: bold; color: red;">=</span> КаталогПрограммы<span class="operator" style="font-weight: bold; color: red;">(</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>

     ПутьКФайлуСкрипта <span class="operator" style="font-weight: bold; color: red;">=</span> КаталогВременныхФайлов<span class="operator" style="font-weight: bold; color: red;">(</span><span class="operator" style="font-weight: bold; color: red;">)</span> <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">"CacheCleaning.vbs"</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     ПутьКФайлу<span class="number" style="color: black;">1</span>С <span class="operator" style="font-weight: bold; color: red;">=</span> СтрокаЗапускаПрограммы <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">"1cv8.exe"</span><span class="operator" style="font-weight: bold; color: red;">;</span>

     ИмяСервера <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">""</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     ИмяБазы <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">""</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     Путь <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">""</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     КомандаЗапуска <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">""</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     Один <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">"<span class="dquote">""</span>"</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     Два <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">"<span class="dquote">""</span><span class="dquote">""</span>"</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     Три <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">"<span class="dquote">""</span><span class="dquote">""</span><span class="dquote">""</span>"</span><span class="operator" style="font-weight: bold; color: red;">;</span>  
    <span class="keyword" style="font-weight: bold; color: red;">Если</span> <span class="operator" style="font-weight: bold; color: red;">(</span>Найти<span class="operator" style="font-weight: bold; color: red;">(</span>СтрокаСоединенияСБД<span class="operator" style="font-weight: bold; color: red;">,</span> <span class="string" style="color: black;">"File="</span><span class="operator" style="font-weight: bold; color: red;">)</span> <span class="operator" style="font-weight: bold; color: red;">&lt;</span><span class="operator" style="font-weight: bold; color: red;">&gt;</span> <span class="number" style="color: black;">0</span><span class="operator" style="font-weight: bold; color: red;">)</span> <span class="keyword" style="font-weight: bold; color: red;">Тогда</span>
          Путь <span class="operator" style="font-weight: bold; color: red;">=</span> СтрЗаменить<span class="operator" style="font-weight: bold; color: red;">(</span>СтрокаСоединенияСБД<span class="operator" style="font-weight: bold; color: red;">,</span> <span class="string" style="color: black;">"File="</span><span class="operator" style="font-weight: bold; color: red;">,</span> <span class="string" style="color: black;">""</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          Путь <span class="operator" style="font-weight: bold; color: red;">=</span> Лев<span class="operator" style="font-weight: bold; color: red;">(</span>Путь<span class="operator" style="font-weight: bold; color: red;">,</span> СтрДлина<span class="operator" style="font-weight: bold; color: red;">(</span>Путь<span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">-</span><span class="number" style="color: black;">1</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          КомандаЗапуска <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">"WshShell.Run "</span> <span class="operator" style="font-weight: bold; color: red;">+</span> Три <span class="operator" style="font-weight: bold; color: red;">+</span> ПутьКФайлу<span class="number" style="color: black;">1</span>С <span class="operator" style="font-weight: bold; color: red;">+</span> Два <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">" ENTERPRISE /F"</span> <span class="operator" style="font-weight: bold; color: red;">+</span> Путь <span class="operator" style="font-weight: bold; color: red;">+</span> Один <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">", 1, true"</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     <span class="keyword" style="font-weight: bold; color: red;">Иначе</span>
          МассивПараметровСоединения <span class="operator" style="font-weight: bold; color: red;">=</span> ОбщегоНазначения<span class="operator" style="font-weight: bold; color: red;">.</span>РазложитьСтрокуВМассивПодстрок<span class="operator" style="font-weight: bold; color: red;">(</span>СтрокаСоединенияИнформационнойБазы<span class="operator" style="font-weight: bold; color: red;">(</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">,</span> <span class="string" style="color: black;">";"</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          МассивПараметровСервера <span class="operator" style="font-weight: bold; color: red;">=</span> ОбщегоНазначения<span class="operator" style="font-weight: bold; color: red;">.</span>РазложитьСтрокуВМассивПодстрок<span class="operator" style="font-weight: bold; color: red;">(</span>МассивПараметровСоединения[<span class="number" style="color: black;">0</span>]<span class="operator" style="font-weight: bold; color: red;">,</span> <span class="string" style="color: black;">"<span class="dquote">""</span>"</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          ИмяСервера <span class="operator" style="font-weight: bold; color: red;">=</span> СокрЛП<span class="operator" style="font-weight: bold; color: red;">(</span>МассивПараметровСервера[<span class="number" style="color: black;">1</span>]<span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          МассивПараметровБазы <span class="operator" style="font-weight: bold; color: red;">=</span> ОбщегоНазначения<span class="operator" style="font-weight: bold; color: red;">.</span>РазложитьСтрокуВМассивПодстрок<span class="operator" style="font-weight: bold; color: red;">(</span>МассивПараметровСоединения[<span class="number" style="color: black;">1</span>]<span class="operator" style="font-weight: bold; color: red;">,</span> <span class="string" style="color: black;">"<span class="dquote">""</span>"</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          ИмяБазы <span class="operator" style="font-weight: bold; color: red;">=</span> СокрЛП<span class="operator" style="font-weight: bold; color: red;">(</span>МассивПараметровБазы[<span class="number" style="color: black;">1</span>]<span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
          КомандаЗапуска <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">"WshShell.Run "</span> <span class="operator" style="font-weight: bold; color: red;">+</span> Три <span class="operator" style="font-weight: bold; color: red;">+</span> ПутьКФайлу<span class="number" style="color: black;">1</span>С <span class="operator" style="font-weight: bold; color: red;">+</span> Два <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">" ENTERPRISE /S"</span> <span class="operator" style="font-weight: bold; color: red;">+</span> ИмяСервера <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">""</span> <span class="operator" style="font-weight: bold; color: red;">+</span> ИмяБазы <span class="operator" style="font-weight: bold; color: red;">+</span> Один <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">", 1, true"</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     <span class="keyword" style="font-weight: bold; color: red;">КонецЕсли</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     <span class="comment" style="color: green;">// Если пользователь не хочет перезапускать сеанс 1С, то после выполнения скрипта ничего не делаем. </span>
     <span class="keyword" style="font-weight: bold; color: red;">Если</span> <span class="keyword" style="font-weight: bold; color: red;">Не</span> глЗначениеПеременной<span class="operator" style="font-weight: bold; color: red;">(</span><span class="string" style="color: black;">"глПерезапускатьСеансРаботыСПрограммой"</span><span class="operator" style="font-weight: bold; color: red;">)</span>  <span class="keyword" style="font-weight: bold; color: red;">Тогда</span>
          КомандаЗапуска <span class="operator" style="font-weight: bold; color: red;">=</span> <span class="string" style="color: black;">""</span><span class="operator" style="font-weight: bold; color: red;">;</span> 
     <span class="keyword" style="font-weight: bold; color: red;">КонецЕсли</span><span class="operator" style="font-weight: bold; color: red;">;</span> 

     СкриптФайл<span class="operator" style="font-weight: bold; color: red;">.</span>УстановитьТекст<span class="operator" style="font-weight: bold; color: red;">(</span><span class="string" style="color: black;">"WScript.Sleep(5000)
     |
     |Dim FSO 
     |Set FSO = WScript.CreateObject(<span class="dquote">""</span>Scripting.FileSystemObject<span class="dquote">""</span>)
     |Set WshShell = WScript.CreateObject(<span class="dquote">""</span>WScript.Shell<span class="dquote">""</span>)
     |Set colEnvVars = WshShell.Environment(<span class="dquote">""</span>Process<span class="dquote">""</span>)
     |
     |strComputer = <span class="dquote">""</span>.<span class="dquote">""</span> 
     |Set objWMIService = GetObject(<span class="dquote">""</span>winmgmts:<span class="dquote">""</span> _ 
     |&amp; <span class="dquote">""</span>{impersonationLevel=impersonate}!\<span class="dquote">""</span> _ 
     |&amp; strComputer &amp; <span class="dquote">""</span>rootcimv2<span class="dquote">""</span>) 
     |
     |Set colProcesses = objWMIService.ExecQuery( _ 
     |<span class="dquote">""</span>S_elect * From Win32_Process <span class="dquote">""</span> _ 
     |&amp; <span class="dquote">""</span>Where Name = '1cv8.exe'<span class="dquote">""</span>) 
     |
     |For Each objProcess In colProcesses 
     | objProcess.Terminate 
     |Next
     | 
     |WScript.Sleep(1000)
     | 
     |FolderName1 = <span class="dquote">""</span>Local SettingsApplication Data1C1Cv82<span class="dquote">""</span>
     |FolderName2 = <span class="dquote">""</span>Local SettingsApplication Data1C1Cv81<span class="dquote">""</span>
     |FolderName3 = <span class="dquote">""</span>appdataLocal1C1Cv82<span class="dquote">""</span>
     |FolderName4 = <span class="dquote">""</span>appdataLocal1C1Cv81<span class="dquote">""</span>
     | 
     |If FSO.FolderExists(colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName1) Then
     | GoSubFolders colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName1
     |End If
     |If FSO.FolderExists(colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName2) Then
     |GoSubFolders colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName2
     | End If
     |If FSO.FolderExists(colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName3) Then
     | GoSubFolders colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName3
     |End If
     |If FSO.FolderExists(colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName4) Then
     | GoSubFolders colEnvVars(<span class="dquote">""</span>userprofile<span class="dquote">""</span>) &amp; FolderName4
     |End If
     |
     |"</span> <span class="operator" style="font-weight: bold; color: red;">+</span> КомандаЗапуска <span class="operator" style="font-weight: bold; color: red;">+</span> <span class="string" style="color: black;">"
     |Set WshShell = Nothing
     | 
     |Sub DelFile(sFILE)
     | On Error Resume Next
     | FSO.DeleteFile sFILE, True
     | If Err.Number &lt;&gt; 0 Then
     | Wscript.Echo <span class="dquote">""</span>Error deleting file: <span class="dquote">""</span> &amp; sFILE
     | End If
     |End sub
     | 
     |Function GetFolder(sFOLDER)
     | On Error Resume Next
     | Set GetFolder = FSO.GetFolder(sFOLDER)
     | If Err.Number &lt;&gt; 0 Then
     | Wscript.Echo <span class="dquote">""</span>Error connecting to folder:<span class="dquote">""</span> &amp; sFOLDER &amp; VBlf &amp; <span class="dquote">""</span>[<span class="dquote">""</span> &amp; Err.Number &amp; <span class="dquote">""</span>]<span class="dquote">""</span> &amp; Err.Description
     | Wscript.Quit Err.Number
     | End If
     |End Function
     | 
     |Sub GoSubFolders (objDIR)
     | ProcessFilesInFolder objDIR
     | Set sFolder = GetFolder(objDIR)
     | For Each eFolder in sFolder.SubFolders
     | GoSubFolders eFolder
     | Next
     | FSO.DeleteFolder sFolder, True
     |End Sub
     |
     |Sub ProcessFilesInFolder (objDIR)
     |Set sFolder = GetFolder(objDIR)
     |For Each objFile in sFolder.Files
     | DelFile objFile
     |Next
     |End Sub"</span><span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>

     <span class="keyword" style="font-weight: bold; color: red;">Попытка</span>
            СкриптФайл<span class="operator" style="font-weight: bold; color: red;">.</span>Записать<span class="operator" style="font-weight: bold; color: red;">(</span>ПутьКФайлуСкрипта<span class="operator" style="font-weight: bold; color: red;">,</span> КодировкаТекста<span class="operator" style="font-weight: bold; color: red;">.</span>Системная<span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
            ЗапуститьПриложение<span class="operator" style="font-weight: bold; color: red;">(</span>ПутьКФайлуСкрипта<span class="operator" style="font-weight: bold; color: red;">)</span><span class="operator" style="font-weight: bold; color: red;">;</span>
     <span class="keyword" style="font-weight: bold; color: red;">Исключение</span>
     <span class="keyword" style="font-weight: bold; color: red;">КонецПопытки</span><span class="operator" style="font-weight: bold; color: red;">;</span>

<span class="keyword" style="font-weight: bold; color: red;">КонецПроцедуры</span>   </code>