Class VolatileResourceCacheService
- java.lang.Object
-
- org.silverpeas.core.cache.service.VolatileResourceCacheService
-
public class VolatileResourceCacheService extends Object
This cache allows to reference some volatile resources (an entity that is being registered into persistence, but not yet validated by the user).
Elements registered with volatile resource are cleared just after the ending of a user session.How it is working:
- first set the identifier of a
Contribution
with a volatile identifier. A volatile identifier is generated by this service (newVolatileStringIdentifier()
for example). The aim of the volatile identifier is to be unique into the context of the application running and not persisted into repositories or at most persisted temporarily - then register the
Contribution
into the service withregister(String, String)
. By this way and for deletion mainly, the elements (attachments for example) will be managed according the user session. -
At user session end:
- If the
Contribution
has been validated, and so registered into repository, theContribution
has no more a volatile identifier but the one given by its manager. So the volatile identifier registered into the cache is pointing no resources and clean process will do nothing in the end. - If the
Contribution
has not been validated, nothing has been persisted into repository. Resources (attachment for example) linked to the volatile identifier will be deleted just after the ending of the user session.
- If the
This above explanations are for understanding. In reality, there just need to use
VolatileIdentifierProvider
to get a volatile identifier.The system does not know services which have to clean resources linked to volatile contributions (so contribution with volatile identifier indeed).
But the system is able to call all implementations ofVolatileResourceCleaner
in order to call the only methodVolatileResourceCleaner.cleanVolatileResources(String, String)
.- Author:
- Yohann Chastagnier
- first set the identifier of a
-
-
Constructor Summary
Constructors Constructor Description VolatileResourceCacheService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears all the resources referenced into this instance of volatile cache.static void
clearFrom(SessionInfo sessionInfo)
Clears the volatile cache attached to a user session.boolean
contains(String volatileId, String componentInstanceId)
Indicates if a contribution exists into the volatile cache with the given identifiers.boolean
contains(Contribution contribution)
Indicates if a contribution exists into the volatile cache.boolean
couldBeVolatileId(String id)
Indicates if the given identifier could be a volatile one.
It works only with identifiers generated bynewVolatileStringIdentifier()
method.
-
-
-
Method Detail
-
clearFrom
public static void clearFrom(SessionInfo sessionInfo)
Clears the volatile cache attached to a user session.- Parameters:
sessionInfo
- the session of a user.
-
contains
public boolean contains(Contribution contribution)
Indicates if a contribution exists into the volatile cache.- Parameters:
contribution
- a contribution instance which contains the volatile identifier.- Returns:
- true if the contribution exists into the volatile cache, false otherwise.
-
couldBeVolatileId
public boolean couldBeVolatileId(String id)
Indicates if the given identifier could be a volatile one.
It works only with identifiers generated bynewVolatileStringIdentifier()
method.- Parameters:
id
- an identifier as string.- Returns:
- true if the identifier is a volatile one, false otherwise.
-
contains
public boolean contains(String volatileId, String componentInstanceId)
Indicates if a contribution exists into the volatile cache with the given identifiers.- Parameters:
volatileId
- the volatile identifier.componentInstanceId
- the identifier of a component instance.- Returns:
- true if the contribution exists into the volatile cache, false otherwise.
-
clear
public void clear()
Clears all the resources referenced into this instance of volatile cache.
-
-