-
Notifications
You must be signed in to change notification settings - Fork 3
/
FileCache.cs
62 lines (53 loc) · 1.53 KB
/
FileCache.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Perforce.P4;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace P4EXP
{
class FileCache
{
private Dictionary<String, FileMetaData> pathToStatMap =
new Dictionary<string, FileMetaData>(StringComparer.InvariantCultureIgnoreCase);
// maintain a cache of file status data
public FileCache()
{
}
public FileMetaData Get(String path)
{
if (pathToStatMap.ContainsKey(path))
return pathToStatMap[path];
return null;
}
public bool Add(IList<FileMetaData> mdl)
{
if (mdl == null)
return false;
foreach (FileMetaData md in mdl)
{
// FileLogger.LogMessage(0, "FileCache", String.Format("{0} added", md.LocalPath.Path));
pathToStatMap[md.LocalPath.Path] = md;
}
return true;
}
public bool Add(FileMetaData fileStatus)
{
// FileLogger.LogMessage(0, "FileCache", String.Format("{0} added", fileStatus.LocalPath.Path));
pathToStatMap[fileStatus.LocalPath.Path] = fileStatus;
return true;
}
public bool Remove(String path)
{
lock (pathToStatMap)
{
return pathToStatMap.Remove(path);
}
}
public void Clear()
{
pathToStatMap.Clear();
}
}
}