Skip to content

Commit

Permalink
Merge pull request #175 from mgoodfellow/hotfix-remove-serializer-cha…
Browse files Browse the repository at this point in the history
…nges

Revert Serializer changes to unblock releases until Protobuf changes implemented
  • Loading branch information
Turnerj authored Aug 7, 2021
2 parents 1afcbc9 + 248515f commit a5718c4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 179 deletions.
14 changes: 0 additions & 14 deletions CacheTower.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheTower.AlternativesBenc
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{FD0B0385-93AD-4DDF-9FE7-C7325B05B6B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheTower.Serializers.Protobuf", "src\CacheTower.Serializers.Protobuf\CacheTower.Serializers.Protobuf.csproj", "{BF88C037-493A-47F2-9B85-C293FC786BEC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheTower.Serializers.NewtonsoftJson", "src\CacheTower.Serializers.NewtonsoftJson\CacheTower.Serializers.NewtonsoftJson.csproj", "{E9066C1E-C042-4707-987E-CF77B311ADB6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -88,14 +84,6 @@ Global
{7830CC14-9FF6-4C56-BBFE-8AE9B6C7AFFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7830CC14-9FF6-4C56-BBFE-8AE9B6C7AFFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7830CC14-9FF6-4C56-BBFE-8AE9B6C7AFFA}.Release|Any CPU.Build.0 = Release|Any CPU
{BF88C037-493A-47F2-9B85-C293FC786BEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF88C037-493A-47F2-9B85-C293FC786BEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF88C037-493A-47F2-9B85-C293FC786BEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF88C037-493A-47F2-9B85-C293FC786BEC}.Release|Any CPU.Build.0 = Release|Any CPU
{E9066C1E-C042-4707-987E-CF77B311ADB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9066C1E-C042-4707-987E-CF77B311ADB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9066C1E-C042-4707-987E-CF77B311ADB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9066C1E-C042-4707-987E-CF77B311ADB6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -110,8 +98,6 @@ Global
{3AD1549A-B386-4AAF-A5A8-FB53F6776CFC} = {E261C038-498E-4F5A-B2D7-B79AB36FFEB0}
{3F2635AA-36AD-4CE3-BD5C-F2301D9351BA} = {E261C038-498E-4F5A-B2D7-B79AB36FFEB0}
{7830CC14-9FF6-4C56-BBFE-8AE9B6C7AFFA} = {FD0B0385-93AD-4DDF-9FE7-C7325B05B6B0}
{BF88C037-493A-47F2-9B85-C293FC786BEC} = {E261C038-498E-4F5A-B2D7-B79AB36FFEB0}
{E9066C1E-C042-4707-987E-CF77B311ADB6} = {E261C038-498E-4F5A-B2D7-B79AB36FFEB0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F159337A-B345-49EE-8D58-A72EF1643174}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<ItemGroup>
<ProjectReference Include="..\CacheTower\CacheTower.csproj" />
<ProjectReference Include="..\CacheTower.Serializers.Protobuf\CacheTower.Serializers.Protobuf.csproj" />
</ItemGroup>

</Project>
6 changes: 2 additions & 4 deletions src/CacheTower.Providers.Redis/Entities/RedisCacheEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Text;
using ProtoBuf;

namespace CacheTower.Providers.Redis.Entities
Expand All @@ -9,20 +10,17 @@ namespace CacheTower.Providers.Redis.Entities
/// </summary>
/// <typeparam name="T">The type of the cached value</typeparam>
[ProtoContract]
[DataContract]
public class RedisCacheEntry<T>
{
/// <summary>
/// The expiry date of the cache entry.
/// </summary>
[ProtoMember(1)]
[DataMember(Name = "expiry")]
public DateTime Expiry { get; set; }
/// <summary>
/// The cached value itself.
/// </summary>
[ProtoMember(2)]
[DataMember(Name = "value")]
public T? Value { get; set; }
}
}
38 changes: 16 additions & 22 deletions src/CacheTower.Providers.Redis/RedisCacheLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,41 @@
using System.IO;
using System.Threading.Tasks;
using CacheTower.Providers.Redis.Entities;
using CacheTower.Serializers.Protobuf;
using ProtoBuf;
using StackExchange.Redis;

namespace CacheTower.Providers.Redis
{
/// <remarks>
/// The <see cref="RedisCacheLayer"/> allows caching data in Redis. Data will be serialized to Protobuf using <a href="https://github.com/protobuf-net/protobuf-net">protobuf-net</a>.
/// <para>
/// When caching custom types, you will need to <a href="https://github.com/protobuf-net/protobuf-net#1-first-decorate-your-classes">decorate your class</a> with <c>[ProtoContact]</c> and <c>[ProtoMember]</c> attributes per protobuf-net's documentation.<br/>
/// Additionally, as the Protobuf format doesn't have a way to represent an empty collection, these will be returned as <c>null</c>.
/// </para>
/// <para>
/// While this can be inconvienent, using Protobuf ensures high performance and low allocations for serializing.
/// </para>
/// </remarks>
/// <inheritdoc cref="ICacheLayer"/>
public class RedisCacheLayer : ICacheLayer
{
private IConnectionMultiplexer Connection { get; }
private IDatabaseAsync Database { get; }
private int DatabaseIndex { get; }
private ICacheSerializer Serializer { get; }

/// <summary>
/// Creates a new instance of <see cref="RedisCacheLayer"/> with the given <paramref name="connection"/> and <paramref name="databaseIndex"/>.
/// If using this constructor, Protobuf encoding will be used.
/// </summary>
/// <param name="connection">The primary connection to Redis where the cache will be stored.</param>
/// <param name="databaseIndex">
/// The database index to use for Redis.
/// If not specified, uses the default database as configured on the <paramref name="connection"/>.
/// </param>
public RedisCacheLayer(IConnectionMultiplexer connection, int databaseIndex = -1) : this(connection, new ProtobufCacheSerializer(), databaseIndex)
{
}

/// <summary>
/// Creates a new instance of <see cref="RedisCacheLayer"/> with the given <paramref name="connection"/> and <paramref name="databaseIndex"/>.
/// </summary>
/// <param name="connection">The primary connection to Redis where the cache will be stored.</param>
/// <param name="serializer">
/// Allows you to specify which encoding should be used by providing your own serializer
/// If one is not provided, ProtobufCacheSerializer will be used
/// </param>
/// <param name="databaseIndex">
/// The database index to use for Redis.
/// If not specified, uses the default database as configured on the <paramref name="connection"/>.
/// </param>
public RedisCacheLayer(IConnectionMultiplexer connection, ICacheSerializer serializer, int databaseIndex = -1)
public RedisCacheLayer(IConnectionMultiplexer connection, int databaseIndex = -1)
{
Connection = connection;
Database = connection.GetDatabase(databaseIndex);
DatabaseIndex = databaseIndex;
Serializer = serializer;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -115,8 +106,11 @@ public async ValueTask SetAsync<T>(string cacheKey, CacheEntry<T> cacheEntry)
Value = cacheEntry.Value!
};

using (var stream = Serializer.Serialize(redisCacheEntry))
using (var stream = new MemoryStream())
{
Serializer.Serialize(stream, redisCacheEntry);
stream.Seek(0, SeekOrigin.Begin);

var redisValue = RedisValue.CreateFrom(stream);
await Database.StringSetAsync(cacheKey, redisValue, expiryOffset);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions src/CacheTower.Serializers.Protobuf/ProtobufCacheSerializer.cs

This file was deleted.

26 changes: 0 additions & 26 deletions src/CacheTower/ICacheSerializer.cs

This file was deleted.

0 comments on commit a5718c4

Please sign in to comment.