Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
bf9eda19
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bf9eda19
编写于
6月 11, 2015
作者:
H
Heejae Chang
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3433 from heejaechang/implicitcache2
fix flaky unit test
上级
0524c566
e110b279
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
21 deletion
+45
-21
src/EditorFeatures/Core/Implementation/Workspaces/ProjectCacheServiceFactory.ProjectCacheService.cs
...kspaces/ProjectCacheServiceFactory.ProjectCacheService.cs
+3
-3
src/EditorFeatures/Core/Implementation/Workspaces/ProjectCacheServiceFactory.SimpleMRUCache.cs
...n/Workspaces/ProjectCacheServiceFactory.SimpleMRUCache.cs
+11
-11
src/EditorFeatures/Test/Workspaces/ProjectCacheHostServiceFactoryTests.cs
...es/Test/Workspaces/ProjectCacheHostServiceFactoryTests.cs
+31
-7
未找到文件。
src/EditorFeatures/Core/Implementation/Workspaces/ProjectCacheServiceFactory.ProjectCacheService.cs
浏览文件 @
bf9eda19
...
...
@@ -54,11 +54,11 @@ public void ClearImplicitCache()
}
}
public
void
ClearExpiredImplicitCache
(
int
expirationTimeInMS
)
public
void
ClearExpiredImplicitCache
(
DateTime
expirationTime
)
{
lock
(
_gate
)
{
_implicitCache
.
ClearExpiredItems
(
expirationTime
InMS
);
_implicitCache
.
ClearExpiredItems
(
expirationTime
);
}
}
...
...
@@ -89,8 +89,8 @@ public IDisposable EnableCaching(ProjectId key)
}
else
if
(!
PartOfP2PReferences
(
key
))
{
_implicitCacheMonitor
?.
Touch
();
_implicitCache
.
Touch
(
instance
);
_implicitCacheMonitor
?.
Touch
();
}
return
instance
;
...
...
src/EditorFeatures/Core/Implementation/Workspaces/ProjectCacheServiceFactory.SimpleMRUCache.cs
浏览文件 @
bf9eda19
...
...
@@ -40,32 +40,32 @@ public bool Empty
public
void
Touch
(
object
instance
)
{
var
oldIndex
=
-
1
;
var
oldTime
=
Environment
.
TickCount
;
var
oldTime
=
DateTime
.
UtcNow
;
for
(
var
i
=
0
;
i
<
nodes
.
Length
;
i
++)
{
if
(
instance
==
nodes
[
i
].
Data
)
{
nodes
[
i
].
LastTouched
InMS
=
Environment
.
TickCount
;
nodes
[
i
].
LastTouched
=
DateTime
.
UtcNow
;
return
;
}
if
(
oldTime
>=
nodes
[
i
].
LastTouched
InMS
)
if
(
oldTime
>=
nodes
[
i
].
LastTouched
)
{
oldTime
=
nodes
[
i
].
LastTouched
InMS
;
oldTime
=
nodes
[
i
].
LastTouched
;
oldIndex
=
i
;
}
}
Contract
.
Requires
(
oldIndex
>=
0
);
nodes
[
oldIndex
]
=
new
Node
(
instance
,
Environment
.
TickCount
);
nodes
[
oldIndex
]
=
new
Node
(
instance
,
DateTime
.
UtcNow
);
}
public
void
ClearExpiredItems
(
int
expirationTimeInMS
)
public
void
ClearExpiredItems
(
DateTime
expirationTime
)
{
for
(
var
i
=
0
;
i
<
nodes
.
Length
;
i
++)
{
if
(
nodes
[
i
].
Data
!=
null
&&
nodes
[
i
].
LastTouched
InMS
<
expirationTimeInMS
)
if
(
nodes
[
i
].
Data
!=
null
&&
nodes
[
i
].
LastTouched
<
expirationTime
)
{
nodes
[
i
]
=
default
(
Node
);
}
...
...
@@ -80,12 +80,12 @@ public void Clear()
private
struct
Node
{
public
readonly
object
Data
;
public
int
LastTouchedInMS
;
public
DateTime
LastTouched
;
public
Node
(
object
data
,
int
lastTouchedInMS
)
public
Node
(
object
data
,
DateTime
lastTouched
)
{
Data
=
data
;
LastTouched
InMS
=
lastTouchedInMS
;
LastTouched
=
lastTouched
;
}
}
}
...
...
@@ -108,7 +108,7 @@ private class ImplicitCacheMonitor : IdleProcessor
protected
override
Task
ExecuteAsync
()
{
_owner
.
ClearExpiredImplicitCache
(
Environment
.
TickCount
-
BackOffTimeSpanInMS
);
_owner
.
ClearExpiredImplicitCache
(
DateTime
.
UtcNow
-
TimeSpan
.
FromMilliseconds
(
BackOffTimeSpanInMS
)
);
return
SpecializedTasks
.
EmptyTask
;
}
...
...
src/EditorFeatures/Test/Workspaces/ProjectCacheHostServiceFactoryTests.cs
浏览文件 @
bf9eda19
...
...
@@ -120,14 +120,35 @@ public void TestImplicitCacheKeepsObjectAlive1()
public
void
TestImplicitCacheMonitoring
()
{
var
cacheService
=
new
ProjectCacheHostServiceFactory
.
ProjectCacheService
(
null
,
10
,
forceCleanup
:
true
);
var
weak
=
PutObjectInImplicitCache
(
cacheService
);
var
timeout
=
TimeSpan
.
FromSeconds
(
10
);
var
current
=
DateTime
.
UtcNow
;
do
{
Thread
.
Sleep
(
100
);
CollectGarbage
();
if
(
DateTime
.
UtcNow
-
current
>
timeout
)
{
break
;
}
}
while
(
weak
.
IsAlive
);
Assert
.
False
(
weak
.
IsAlive
);
GC
.
KeepAlive
(
cacheService
);
}
private
static
WeakReference
PutObjectInImplicitCache
(
ProjectCacheHostServiceFactory
.
ProjectCacheService
cacheService
)
{
var
instance
=
new
object
();
var
weak
=
new
WeakReference
(
instance
);
cacheService
.
CacheObjectIfCachingEnabledForKey
(
ProjectId
.
CreateNewId
(),
(
object
)
null
,
instance
);
instance
=
null
;
Thread
.
Sleep
(
100
);
CollectGarbage
();
Assert
.
False
(
weak
.
IsAlive
);
GC
.
KeepAlive
(
cacheService
);
return
weak
;
}
[
Fact
]
...
...
@@ -224,9 +245,12 @@ private class Owner : ICachedObjectOwner
private
static
void
CollectGarbage
()
{
GC
.
Collect
();
GC
.
WaitForPendingFinalizers
();
GC
.
Collect
();
for
(
var
i
=
0
;
i
<
10
;
i
++)
{
GC
.
Collect
();
GC
.
WaitForPendingFinalizers
();
GC
.
Collect
();
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录