-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade dependencies and target frameworks (#147)
* Upgrade dependencies and target frameworks * Update .travis.yml * IStorage (#148) * Fix UT (#149) * Update RpcNep5Tracker/RpcNep5Tracker.cs Co-Authored-By: Erik Zhang <erik@neo.org> * Update RpcNep5Tracker/RpcNep5Tracker.cs Co-Authored-By: Erik Zhang <erik@neo.org> * Update RpcNep5Tracker/RpcNep5Tracker.cs Co-Authored-By: Erik Zhang <erik@neo.org>
- Loading branch information
Showing
16 changed files
with
109 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Neo.IO; | ||
using Neo.IO.Caching; | ||
using Neo.IO.Data.LevelDB; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Neo.Plugins | ||
{ | ||
public class DbCache<TKey, TValue> : DataCache<TKey, TValue> | ||
where TKey : IEquatable<TKey>, ISerializable, new() | ||
where TValue : class, ICloneable<TValue>, ISerializable, new() | ||
{ | ||
private readonly DB db; | ||
private readonly ReadOptions options; | ||
private readonly WriteBatch batch; | ||
private readonly byte prefix; | ||
|
||
public DbCache(DB db, ReadOptions options, WriteBatch batch, byte prefix) | ||
{ | ||
this.db = db; | ||
this.options = options ?? ReadOptions.Default; | ||
this.batch = batch; | ||
this.prefix = prefix; | ||
} | ||
|
||
protected override void AddInternal(TKey key, TValue value) | ||
{ | ||
batch?.Put(prefix, key, value); | ||
} | ||
|
||
protected override void DeleteInternal(TKey key) | ||
{ | ||
batch?.Delete(prefix, key); | ||
} | ||
|
||
protected override IEnumerable<(TKey, TValue)> FindInternal(byte[] key_prefix) | ||
{ | ||
return db.Find(options, SliceBuilder.Begin(prefix).Add(key_prefix), (k, v) => (k.ToArray().AsSerializable<TKey>(1), v.ToArray().AsSerializable<TValue>())); | ||
} | ||
|
||
protected override TValue GetInternal(TKey key) | ||
{ | ||
return db.Get<TValue>(options, prefix, key); | ||
} | ||
|
||
protected override TValue TryGetInternal(TKey key) | ||
{ | ||
return db.TryGet<TValue>(options, prefix, key); | ||
} | ||
|
||
protected override void UpdateInternal(TKey key, TValue value) | ||
{ | ||
batch?.Put(prefix, key, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.