Legacy and PerBrowser implementations

This commit is contained in:
Alex Maitland
2023-04-12 13:38:46 +10:00
parent 1533ba2db6
commit f964bbc08e
4 changed files with 103 additions and 31 deletions
@@ -0,0 +1,50 @@
// Copyright © 2023 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.Collections.Generic;
namespace CefSharp.Internals
{
/// <summary>
/// Render Process JavaScript Binding (JSB) object cache
/// Legacy Behaviour, objects are cache per process.
/// </summary>
public class LegacyJavaScriptObjectCache : IJavaScriptObjectCache
{
private readonly Dictionary<string, JavascriptObject> cache
= new Dictionary<string, JavascriptObject>();
/// <inheritdoc/>
public void ClearCache(int browserId)
{
// NO OP
}
/// <inheritdoc/>
public void InsertOrUpdate(int browserId, IList<JavascriptObject> javascriptObjects)
{
foreach (var obj in javascriptObjects)
{
if (cache.ContainsKey(obj.Name))
{
cache.Remove(obj.Name);
}
cache.Add(obj.Name, obj);
}
}
/// <inheritdoc/>
public ICollection<JavascriptObject> GetCacheValues(int browserId)
{
return cache.Values;
}
/// <inheritdoc/>
public Dictionary<string, JavascriptObject> GetCache(int browserId)
{
return cache;
}
}
}