FlushDirectory() public static méthode

public static FlushDirectory ( string path ) : void
path string
Résultat void
Exemple #1
0
 public static void EnableWebCache(string path)
 {
     if (WebCachePath != null && (path != WebCachePath && path != null))
     {
         BlobStore.FlushDirectory(WebCachePath);
         BlobStore.CloseDirectory(WebCachePath);
     }
     if (path != null)
     {
         path = Path.GetFullPath(path);
         Directory.CreateDirectory(path);
     }
     WebCachePath = path;
 }
Exemple #2
0
        internal static void SaveCache(string cachePath, WebCache webCache)
        {
            if (cachePath == null || webCache == null)
            {
                return;
            }

            using (var stream = BlobStore.OpenWrite(cachePath))
            {
                using (var gz = new GZipStream2(stream, CompressionMode.Compress))
                    using (var bw = new BinaryWriter(gz, Encoding.UTF8))
                    {
                        Sanity.AssertFastWriteByte(gz.BaseStream);
                        bw.Write((byte)52);
                        bw.WriteNullableString(webCache.ContentType);
                        bw.Write(webCache.DateRetrieved.Ticks);
                        bw.Write(webCache.ErrorCode);
                        bw.WriteNullableString(webCache.ExceptionMessage);
                        bw.WriteNullableString(webCache.ExceptionType);
                        bw.Write(webCache.Headers != null ? webCache.Headers.Count : 0);
                        if (webCache.Headers != null)
                        {
                            foreach (var item in webCache.Headers)
                            {
                                bw.Write(item.Key);
                                bw.Write(item.Value);
                            }
                        }

                        bw.Write(webCache.Cookies != null ? webCache.Cookies.Count : 0);
                        if (webCache.Cookies != null)
                        {
                            foreach (var item in webCache.Cookies)
                            {
                                bw.Write(item.Key);
                                bw.Write(item.Value);
                            }
                        }

                        bw.Write((byte)webCache.DataType);
                        bw.WriteNullableString(webCache.RedirectUrl != null ? webCache.RedirectUrl.AbsoluteUri : null);
                        bw.WriteNullableString(webCache.Url != null ? webCache.Url.AbsoluteUri : null);
                        bw.WriteNullableString(webCache.Result);
                        bw.WriteNullableString(webCache.JsExecutionResults);
                        bw.WriteNullableString(webCache.PageUrl?.AbsoluteUri);
                    }
            }

            if (lastFlush == null)
            {
                lastFlush = Stopwatch.StartNew();
            }
            else if (lastFlush.ElapsedMilliseconds > Configuration_FlushIntervalMs)
            {
                BlobStore.FlushDirectory(Path.GetDirectoryName(cachePath));
#if NET35
                lastFlush.Stop();
                lastFlush.Start();
#else
                lastFlush.Restart();
#endif
            }
        }