FTP Session Caching
从 Spring Integration 3.0 开始,不再默认缓存会话。端点上不再支持 cache-sessions
特性。如果您希望缓存会话,您必须使用 CachingSessionFactory
(在随后的示例中展示)。
Starting with Spring Integration 3.0, sessions are no longer cached by default.
The cache-sessions
attribute is no longer supported on endpoints.
You must use a CachingSessionFactory
(shown in the next example) if you wish to cache sessions.
在 3.0之前的版本中,会话默认情况下会自动缓存。cache-sessions
属性可用于禁用自动缓存,但该解决方案并没有提供一种配置其他会话缓存属性的方法。例如,你无法限制创建的会话数。为了支持该要求和其他配置选项,添加了 CachingSessionFactory
。它提供 sessionCacheSize
和 sessionWaitTimeout
属性。sessionCacheSize
属性控制工厂在其缓存中维护多少个活动会话(默认情况下无限制)。如果已达到 sessionCacheSize
阈值,则获取另一个会话的任何尝试都将阻塞,直到其中一个缓存会话变为可用或会话等待时间到期(默认等待时间为 Integer.MAX_VALUE
)。sessionWaitTimeout
属性配置该值。
In versions prior to 3.0, the sessions were automatically cached by default.
A cache-sessions
attribute was available for disabling the auto caching, but that solution did not provide a way to configure other session caching attributes.
For example, you could not limit the number of sessions created.
To support that requirement and other configuration options, a CachingSessionFactory
was added.
It provides sessionCacheSize
and sessionWaitTimeout
properties.
The sessionCacheSize
property controls how many active sessions the factory maintains in its cache (the default is unbounded).
If the sessionCacheSize
threshold has been reached, any attempt to acquire another session blocks until either one of the cached sessions becomes available or until the wait time for a session expires (the default wait time is Integer.MAX_VALUE
).
The sessionWaitTimeout
property configures that value.
如果希望缓存会话,请按前面所述配置你的默认会话工厂,然后将其包装在 CachingSessionFactory
实例中,你可以在其中提供这些附加属性。以下示例演示如何执行此操作:
If you want your sessions to be cached, configure your default session factory as described earlier and then wrap it in an instance of CachingSessionFactory
, where you can provide those additional properties.
The following example shows how to do so:
<bean id="ftpSessionFactory" class="o.s.i.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="localhost"/>
</bean>
<bean id="cachingSessionFactory" class="o.s.i.file.remote.session.CachingSessionFactory">
<constructor-arg ref="ftpSessionFactory"/>
<constructor-arg value="10"/>
<property name="sessionWaitTimeout" value="1000"/>
</bean>
前一个示例显示了创建一个 CachingSessionFactory
,其中 sessionCacheSize
设置为 10
,sessionWaitTimeout
设置为一秒(其值为毫秒)。
The preceding example shows a CachingSessionFactory
created with the sessionCacheSize
set to 10
and the sessionWaitTimeout
set to one second (its value is in milliseconds).
从 Spring Integration 3.0 开始,CachingConnectionFactory
提供了 resetCache()
方法。调用时,所有空闲会话都会立即关闭,而正在使用的会话会在返回到缓存时关闭。对会话的新请求将根据需要建立新的会话。
Starting with Spring Integration 3.0, the CachingConnectionFactory
provides a resetCache()
method.
When invoked, all idle sessions are immediately closed and in-use sessions are closed when they are returned to the cache.
New requests for sessions establish new sessions as necessary.
自版本 5.1 起,CachingSessionFactory
有一个新特性 testSession
。为 true 时,会话会通过发送 NOOP 命令来经过测试,以确保它依然活跃;如果不活跃,它会从缓存中移除;如果没有活跃会话存在于缓存中,将会创建一个新会话。
Starting with version 5.1, the CachingSessionFactory
has a new property testSession
.
When true, the session will be tested by sending a NOOP command to ensure it is still active; if not, it will be removed from the cache; a new session is created if no active sessions are in the cache.