-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRevisions.cs
41 lines (36 loc) · 1.47 KB
/
Revisions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
namespace Sophie.Cache
{
/// <summary>
/// Revisions contains a cache that holds multiple instances of the same type that represent
/// copies that very by modifications made
/// </summary>
/// <typeparam name="T">The class type of the revision. One set of revisions per type.</typeparam>
public class Revisions<T> where T : IItem<T>
{
private readonly List<T> _keep = new List<T>();
private readonly List<string> _keys = new List<string>();
private readonly Cacher<List<T>> _revisions = new Cacher<List<T>>();
/// <summary>Retrieves all of the updates of an instance of type T</summary>
/// <param name="id">The instance id to fetch revisions</param>
/// <returns>A list of all revisions [copies] of instance identified by id</returns>
public virtual IEnumerable<T> FetchAll(Guid id)
{
return _revisions.Fetch(id);
}
/// <summary>Adds a revision to the cache</summary>
/// <param name="value">The value [copy] to insert</param>
public virtual void Insert(T value)
{
var revisions = _revisions.Fetch(value.Instance);
if (revisions == null)
{
revisions = new List<T>();
_revisions.Insert(value.Instance, revisions);
}
revisions.Add(value);
_revisions.Insert(value.Instance, revisions);
}
}
}