Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to clear cache in Jira using CachManager class

Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012
 
I need to clear Lucene cache before reinexing issue.
I found that in previous versions clear caching and reindexing was done as following: 
boolean wasIndexing = ImportUtils.isIndexIssues();
    ImportUtils.setIndexIssues(true);
    ManagerFactory.getCacheManager().flush(CacheManager.ISSUE_CACHE, issue)
    log.debug("Reindex issue ${issue.key}")
    indexManager.reIndex(issue);
    ImportUtils.setIndexIssues(wasIndexing)

I am using Jira 5.0.5.

what is the coorect way in Jira 5 to run :

ManagerFactory.getCacheManager().flush(CacheManager.ISSUE_CACHE, issue)


Thanks
 

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

Flushing cache manager is no more needed in JIRA5. It wasn't doing anything in the later versions of JIRA too. Try this:

boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
//Do your changes on issue here!   
log.debug("Reindex issue ${issue.key}")
indexManager.reIndex(issue);
ImportUtils.setIndexIssues(wasIndexing)

Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

hi Jubin,

I have tried that many times, reindex command runs with no exceptions

but Lucene is not updated.

(in my plugin I update issue status in code. The status is updated correctly in DB but when I search the updated issue using JQL or IssueNavigator I get the issue with old status)

when I run manually reindexAll() everything get fixed but this operation takes alot of time which is not acceptable on end users

Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

file : (code.txt)

Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

my code comes from EventListener when event is updated I check if in linked event status was updates and I update status:

see attached file with full code

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

Are you doing the changes to the issue where I have the comment? From your code, you are not doing any issue changes there. Maybe posting the full code will help.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

Attachment missing..

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

2 changes. Reindex transResult.getIssue and not newIssue. This might be causing the problem.

Second change, I don't see you are using wasIndexing. You are setting it to true, which is a bad practice. Get the original indexing status, temporarily change to true and set it back to what it was!

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

I wonder if you have some other listener or code doing an indexing after this one the old issue object! Can't think of anything else.

Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

Hi Jubin,

changed checkAndUpdateStatuses method got same results after search( I get old status) .

updated code:

IssueIndexManager indexManager= ComponentAccessor.getIssueIndexManager();
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
 
int actionid;
IssueService issueService=ComponentAccessor.getIssueService();
actionid=getActionIdForTransition(newIssue,transitionname);
IssueInputParameters issueInputParams= issueService.newIssueInputParameters();
issueInputParams.setComment("changed by: " + authContext.getLoggedInUser());
TransitionValidationResult transValidResult=issueService.validateTransition( authContext.getLoggedInUser(),newIssue.getId(), actionid,issueInputParams);
if(transValidResult.isValid())
{
     IssueResult transResult=issueService.transition(authContext.getLoggedInUser(), transValidResult);
      if(transResult.isValid())
         {
 		indexManager.reIndex(transResult.getIssue());
		ImportUtils.setIndexIssues(wasIndexing);
           }
}

Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

thanks a lot Jubin!!!!

You was right I made reindexing twice inside checkAndUpdateStatuses method and afer executing this method.

How is that doing reindexing twice is reverting the index?

notice that in both cases I reindex the new issue (after changing it's status)

the important thing that is working :)

MohammadA April 16, 2014

what if I want to reindex not an issue but something else like custom field. suppose I am adding NEW option to select list and I dont want to restart my jira but want to reset cache. I assume this one would only help for individual issue.

0 votes
Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

:)

I saw my misspelling :)

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

@NirZ - It was a joke.

0 votes
Nir Zolotorevsky
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

what do you mean ?

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

@Radu What currency do you prefer?

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2012

CashManager ? That one should be filled, not emptied !!!! :))

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events