Skip to content

Commit

Permalink
Update TFM's to remove Net 7.0 (#954)
Browse files Browse the repository at this point in the history
Fix Package Icon from Url to use local resource
Include Readme in package
Update code to use latest coding optimisations
  • Loading branch information
ChrisPulman committed Sep 12, 2024
1 parent 0f8294d commit 59922a0
Show file tree
Hide file tree
Showing 24 changed files with 392 additions and 96 deletions.
Binary file added Images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/Akavache.Core/BlobCache/CacheEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Akavache;
/// <param name="expiresAt">The date and time when the entry expires.</param>
public class CacheEntry(string? typeName, byte[] value, DateTimeOffset createdAt, DateTimeOffset? expiresAt)
{

/// <summary>
/// Gets or sets the date and time when the entry was created.
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions src/Akavache.Core/BlobCache/IObjectWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ namespace Akavache;
/// <summary>
/// A wrapper around a object.
/// </summary>
internal interface IObjectWrapper
{
}
internal interface IObjectWrapper;
4 changes: 1 addition & 3 deletions src/Akavache.Core/BlobCache/ISecureBlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ namespace Akavache;
/// saved to disk cannot be easily read by a third party.
/// </para>
/// </summary>
public interface ISecureBlobCache : IBlobCache
{
}
public interface ISecureBlobCache : IBlobCache;
28 changes: 14 additions & 14 deletions src/Akavache.Core/BlobCache/InMemoryBlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public InMemoryBlobCache(IEnumerable<KeyValuePair<string, byte[]>> initialConten
public InMemoryBlobCache(IScheduler? scheduler, IEnumerable<KeyValuePair<string, byte[]>>? initialContents)
{
Scheduler = scheduler ?? CurrentThreadScheduler.Instance;
foreach (var item in initialContents ?? Enumerable.Empty<KeyValuePair<string, byte[]>>())
foreach (var item in initialContents ?? [])
{
_cache[item.Key] = new(null, item.Value, Scheduler.Now, null);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public IObservable<Unit> Insert(string key, byte[] data, DateTimeOffset? absolut
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand All @@ -168,15 +168,15 @@ public IObservable<Unit> Insert(string key, byte[] data, DateTimeOffset? absolut

/// <inheritdoc />
public IObservable<Unit> Flush() => _disposed ?
ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache") :
ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache)) :
Observable.Return(Unit.Default);

/// <inheritdoc />
public IObservable<byte[]> Get(string key)
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<byte[]>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<byte[]>(nameof(InMemoryBlobCache));
}

CacheEntry? entry;
Expand Down Expand Up @@ -211,7 +211,7 @@ public IObservable<byte[]> Get(string key)
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<DateTimeOffset?>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<DateTimeOffset?>(nameof(InMemoryBlobCache));
}

CacheEntry? entry;
Expand All @@ -233,7 +233,7 @@ public IObservable<IEnumerable<string>> GetAllKeys()
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<List<string>>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<List<string>>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand All @@ -250,7 +250,7 @@ public IObservable<Unit> Invalidate(string key)
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand All @@ -266,7 +266,7 @@ public IObservable<Unit> InvalidateAll()
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand All @@ -282,7 +282,7 @@ public IObservable<Unit> InsertObject<T>(string key, T value, DateTimeOffset? ab
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache));
}

var data = SerializeObject(value);
Expand All @@ -300,7 +300,7 @@ public IObservable<T> GetObject<T>(string key)
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<T>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<T>(nameof(InMemoryBlobCache));
}

CacheEntry? entry;
Expand Down Expand Up @@ -340,7 +340,7 @@ public IObservable<IEnumerable<T>> GetAllObjects<T>()
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<IEnumerable<T>>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<IEnumerable<T>>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand All @@ -356,15 +356,15 @@ public IObservable<IEnumerable<T>> GetAllObjects<T>()

/// <inheritdoc />
public IObservable<Unit> InvalidateObject<T>(string key) => _disposed ?
ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache") :
ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache)) :
Invalidate(key);

/// <inheritdoc />
public IObservable<Unit> InvalidateAllObjects<T>()
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand All @@ -384,7 +384,7 @@ public IObservable<Unit> Vacuum()
{
if (_disposed)
{
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("InMemoryBlobCache");
return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>(nameof(InMemoryBlobCache));
}

lock (_cache)
Expand Down
4 changes: 1 addition & 3 deletions src/Akavache.Core/IsExternalInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
namespace System.Runtime.CompilerServices;

[EditorBrowsable(EditorBrowsableState.Never)]
internal class IsExternalInit
{
}
internal class IsExternalInit;
4 changes: 1 addition & 3 deletions src/Akavache.Sqlite3/IsExternalInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
namespace System.Runtime.CompilerServices;

[EditorBrowsable(EditorBrowsableState.Never)]
internal class IsExternalInit
{
}
internal class IsExternalInit;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ namespace Akavache.Sqlite3;

// NB: This just makes OperationQueue's life easier by giving it a type
// name.
internal class BulkInvalidateByTypeSqliteOperation(SQLiteConnection conn) : BulkInvalidateSqliteOperation(conn, true)
{
}
internal class BulkInvalidateByTypeSqliteOperation(SQLiteConnection conn) : BulkInvalidateSqliteOperation(conn, true);
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BulkInvalidateSqliteOperation(SQLiteConnection conn, bool useTypeInsteadO

public Action PrepareToExecute(IEnumerable<string>? toDelete)
{
var deleteList = (toDelete ?? Array.Empty<string>()).ToList();
var deleteList = (toDelete ?? []).ToList();
if (deleteList.Count == 0)
{
return () => { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@

namespace Akavache.Sqlite3;

internal class BulkSelectByTypeSqliteOperation(SQLiteConnection conn, IScheduler scheduler) : BulkSelectSqliteOperation(conn, true, scheduler)
{
}
internal class BulkSelectByTypeSqliteOperation(SQLiteConnection conn, IScheduler scheduler) : BulkSelectSqliteOperation(conn, true, scheduler);
4 changes: 2 additions & 2 deletions src/Akavache.Sqlite3/Operations/BulkSelectSqliteOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public BulkSelectSqliteOperation(SQLiteConnection conn, bool useTypeInsteadOfKey

public Func<IEnumerable<CacheElement>> PrepareToExecute(IEnumerable<string>? toSelect)
{
var selectList = (toSelect ?? Array.Empty<string>()).ToList();
var selectList = (toSelect ?? []).ToList();
if (selectList.Count == 0)
{
return () => new List<CacheElement>();
return () => [];
}

var selectOp = _selectOps[selectList.Count - 1];
Expand Down
2 changes: 1 addition & 1 deletion src/Akavache.Sqlite3/Queues/OperationQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public void Dispose()
_shouldQuit?.Dispose();
}

internal List<OperationQueueItem> DumpQueue() => _operationQueue.ToList();
internal List<OperationQueueItem> DumpQueue() => [.. _operationQueue];

private static void MarshalCompletion(object completion, Action block, IObservable<Unit> commitResult)
{
Expand Down
47 changes: 21 additions & 26 deletions src/Akavache.Sqlite3/Queues/OperationQueueCoalescing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ internal static List<OperationQueueItem> CoalesceOperations(List<OperationQueueI
foreach (var v in inputItems)
{
var key = GetKeyFromTuple(v) ?? NullKey;
if (!groupedOps.ContainsKey(key))
if (!groupedOps.TryGetValue(key, out var value))
{
groupedOps.Add(key, new());
value = [];
groupedOps.Add(key, value);
}

var list = groupedOps[key];
var list = value;
list.Add(v);
}

Expand Down Expand Up @@ -102,9 +103,9 @@ private static IEnumerable<OperationQueueItem> CoalesceUnrelatedItems(IEnumerabl
items.GroupBy(x => x.OperationType)
.SelectMany(group => group.Key switch
{
OperationType.BulkSelectSqliteOperation => new[] { GroupUnrelatedSelects(group) },
OperationType.BulkInsertSqliteOperation => new[] { GroupUnrelatedInserts(group) },
OperationType.BulkInvalidateSqliteOperation => new[] { GroupUnrelatedDeletes(group) },
OperationType.BulkSelectSqliteOperation => [GroupUnrelatedSelects(group)],
OperationType.BulkInsertSqliteOperation => [GroupUnrelatedInserts(group)],
OperationType.BulkInvalidateSqliteOperation => [GroupUnrelatedDeletes(group)],
_ => (IEnumerable<OperationQueueItem>)group
});

Expand All @@ -116,7 +117,7 @@ private static IEnumerable<OperationQueueItem> MultipleOpsTurnIntoSingleOp(IEnum
{
if (item.OperationType == opTypeToDedup)
{
currentWrites ??= new();
currentWrites ??= [];
currentWrites.Add(item);
continue;
}
Expand Down Expand Up @@ -185,9 +186,7 @@ private static OperationQueueItem GroupUnrelatedSelects(IEnumerable<OperationQue
{
try
{
elementMap[v].OnNext(resultMap.ContainsKey(v)
? EnumerableEx.Return(resultMap[v])
: Enumerable.Empty<CacheElement>());
elementMap[v].OnNext(resultMap.TryGetValue(v, out var value) ? EnumerableEx.Return(value) : []);
elementMap[v].OnCompleted();
}
Expand Down Expand Up @@ -228,7 +227,7 @@ private static OperationQueueItem GroupUnrelatedInserts(IEnumerable<OperationQue
var elements = operationQueueItems.SelectMany(x =>
{
subj.Subscribe(x.CompletionAsUnit);
return x.ParametersAsElements ?? Enumerable.Empty<CacheElement>();
return x.ParametersAsElements ?? [];
}).ToList();

return OperationQueueItem.CreateInsert(
Expand Down Expand Up @@ -259,7 +258,7 @@ private static OperationQueueItem GroupUnrelatedDeletes(IEnumerable<OperationQue
var elements = operationQueueItems.SelectMany(x =>
{
subj.Subscribe(x.CompletionAsUnit);
return x.ParametersAsKeys ?? Enumerable.Empty<string>();
return x.ParametersAsKeys ?? [];
}).ToList();

return OperationQueueItem.CreateInvalidate(
Expand Down Expand Up @@ -292,21 +291,17 @@ private static OperationQueueItem GroupUnrelatedDeletes(IEnumerable<OperationQue

private static object CombineSubjectsByOperation(object source, IEnumerable<object>? subjects, OperationType opType)
{
var subjectsList = (subjects ?? Enumerable.Empty<object>()).ToList();
switch (opType)
var subjectsList = (subjects ?? []).ToList();
return opType switch
{
case OperationType.BulkSelectSqliteOperation:
return CombineSubjects(
(AsyncSubject<IEnumerable<CacheElement>>)source,
subjectsList.Cast<AsyncSubject<IEnumerable<CacheElement>>>());
case OperationType.BulkInsertSqliteOperation:
case OperationType.BulkInvalidateSqliteOperation:
return CombineSubjects(
(AsyncSubject<Unit>)source,
subjectsList.Cast<AsyncSubject<Unit>>());
default:
throw new ArgumentException("Invalid operation type", nameof(opType));
}
OperationType.BulkSelectSqliteOperation => CombineSubjects(
(AsyncSubject<IEnumerable<CacheElement>>)source,
subjectsList.Cast<AsyncSubject<IEnumerable<CacheElement>>>()),
OperationType.BulkInsertSqliteOperation or OperationType.BulkInvalidateSqliteOperation => CombineSubjects(
(AsyncSubject<Unit>)source,
subjectsList.Cast<AsyncSubject<Unit>>()),
_ => throw new ArgumentException("Invalid operation type", nameof(opType)),
};
}

private static AsyncSubject<T> CombineSubjects<T>(AsyncSubject<T> source, IEnumerable<AsyncSubject<T>> subjs)
Expand Down
4 changes: 1 addition & 3 deletions src/Akavache.Sqlite3/SqlLiteCache/IObjectWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ namespace Akavache.Sqlite3;
/// <summary>
/// A wrapper around a object.
/// </summary>
internal interface IObjectWrapper
{
}
internal interface IObjectWrapper;
5 changes: 1 addition & 4 deletions src/Akavache.Sqlite3/SqlLiteCache/ObjectWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public ObjectWrapper()
{
}

public ObjectWrapper(T value)
{
Value = value;
}
public ObjectWrapper(T value) => Value = value;

public T? Value { get; set; }
}
Loading

0 comments on commit 59922a0

Please sign in to comment.