查看MemoryCache的文档,我预计如果在Expiration期间访问了一个对象,则会刷新该期间.说实话,我认为我从"滑动"这个名称推断出的东西和任何东西一样多.
但是,从这个测试看来
[Test]
public void SlidingExpiryNotRefreshedOnTouch()
{
var memoryCache = new MemoryCache("donkey")
{
{
"1",
"jane",
new CacheItemPolicy {SlidingExpiration = TimeSpan.FromSeconds(1) }
}
};
var enumerable = Enumerable.Repeat("1", 100)
.TakeWhile((id, index) =>
{
Thread.Sleep(100);
return memoryCache.Get(id) != null; // i.e. it still exists
})
.Select((id, index) => (index+2)*100.0/1000); // return the elapsed time
var expires = enumerable.Last(); // gets the last existing entry
expires.Should().BeGreaterThan(1.0);
}
Run Code Online (Sandbox Code Playgroud)
它失败并显示一旦TimeSpan完成后对象被弹出的行为,无论对象是否已被访问.Linq查询在enumerable.Last()中执行; 语句,此时缓存尚未过期.一旦停止,列表中的最后一项将指示项目在缓存中存在多长时间.
对于Clarity这个问题是关于MemoryCache的行为.不是linq查询.
这是否是其他人的期望(即每次触摸时过期不会滑动)?是否有一种模式可以延长"触摸"对象的生命周期?
更新我发现即使我在缓存周围写了一个包装器,并且每次检索它时都将对象重新添加回缓存,而另一个SlidingExpiration仍然只支持初始设置.为了让它以我想要的方式工作,我必须在重新添加它之前将其从缓存中删除!这可能在多线程环境中导致不期望的竞争条件.
我有以下插件用于创建-sources.jar和部署特定命名jar到存储库.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<configuration>
<version>${project.version}-r${buildNumber}</version>
<classifier>${env}</classifier>
<packaging>jar</packaging>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
<url>${artifactory.url}/libs-release-local</url>
<repositoryId>artifactory.digiterre.com</repositoryId>
<pomFile>${project.basedir}/pom.xml</pomFile>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我希望同时部署它*-sources.jar.我尝试添加第二个文件条目甚至第二个部署插件.我似乎部署了一个或其他文件.
是否可以在一次通过中使用deploy:deploy-file或者我是否必须设置第二个团队城市构建才能部署源?
我的项目使用Guice作为IOC容器,负责为大对象(主要是单例)提供依赖关系(服务类).有时,如果在构造期间依赖项失败并且许多对象需要此依赖项,则会一次又一次地将失败添加到Guice中ProvisionException.
我可以理解这种行为的合理性,因为它列出了为节省修复问题而发生的所有错误.但是,我想禁用此功能并"快速失败",因为在这种情况下重复失败是资源密集型的.此外,'ProvisionException'包含相同异常的列表.
我确实感谢这种行为是在实现中(即资源密集型对象创建)的不良实践的症状(气味),但由于依赖性是任何人都可以使用依赖注入提供实现和插件的抽象,因此几乎没有防御它.
我想知道的是: -
是否有一个参数使Guice能够在第一个异常时退出Injector创建?
任何帮助将不胜感激.
编辑:
@Test
public void guiceExample()
{
Injector injector = Guice.createInjector(new TestModule());
try{
IAmANeedyObject instance = injector.getInstance(IAmANeedyObject.class);
}
catch (ProvisionException e)
{
assertThat(e.getErrorMessages().size(),Is.is(2));
}
}
Run Code Online (Sandbox Code Playgroud)
此测试资产已抛出两个异常
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
public class TestModule extends AbstractModule {
@Override
protected void configure() {
bind(IWasDesignedWithHonestIntent.class).to(NastyThrowingExample.class);
bind(IMindMyOwnBusiness.class).to(SomeLucklessObject.class);
bind(IAlsoMindMyOwnBusiness.class).to(SomeEquallyLucklessObject.class);
bind(IAmANeedyObject.class).to(LowSelfEsteem.class);
}
}
interface IWasDesignedWithHonestIntent {}
interface IMindMyOwnBusiness {}
interface IAlsoMindMyOwnBusiness {}
interface IAmANeedyObject {}
@Singleton
class NastyThrowingExample implements IWasDesignedWithHonestIntent {
@Inject
public NastyThrowingExample() throws LongSlowAgonisingDeathException …Run Code Online (Sandbox Code Playgroud)