Answers.Body: <p>CRM_Core_PseudoConstant::flush() should do it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-18T04:10:03.597Z
Answers.LastActivityDate: 2015-04-18T04:10:03.597Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>You can manually clear caches with <code>civicrm_api3('AnyEntity', 'getfields', array('cache_clear' =&gt; 1));</code> (use any valid entity, it doesn't matter which).</p>
  
  <p>However, if you are using the api to create tags, and this does not automatically clear the cached list of tags, I would consider it a bug. If you are able to reproduce it in the latest version please look in the <a href="https://issues.civicrm.org" rel="nofollow">issue tracker</a> for an open bug report, and if there isn't one, please open one.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-20T14:29:41.550Z
Answers.Text: This worked. We're running 4.4.x. I diffed the tag-related api files between 4.4 and 4.6 and don't see any changes that would suggest the tags cache is cleared or rebuilt after creation.
Answers.UserDisplayName: lcdservices
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-19T19:44:13.947Z
Answers.LastActivityDate: 2015-04-19T19:44:13.947Z
Answers.UserDisplayName: Coleman
Body: <p>I find that if I create a new tag via the api, and then try to attach it to a contact with the entity_tag api, it will sometimes fail with the message "'##' is not a valid option for field tag_id".</p>
  
  <p>This is because the entity_tag api checks for the existence of the tag_id using a pseudoconstant lookup -- which is a cached value. How can I easily clear that pseudoconstant cache after the tag has been created to ensure it can be added to the entity?</p>
  
Tags: <api><cache>
Title: How to clear pseudoconstant cache?
ThreadText: # How to clear pseudoconstant cache?
  
  (Asked by: username_0 on 2015-04-17)
  
  I find that if I create a new tag via the api, and then try to attach it to a contact with the entity\_tag api, it will sometimes fail with the message "'##' is not a valid option for field tag\_id".
  
  This is because the entity\_tag api checks for the existence of the tag\_id using a pseudoconstant lookup -- which is a cached value. How can I easily clear that pseudoconstant cache after the tag has been created to ensure it can be added to the entity?
  
  **Tags:** api, cache
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-04-19. Score: 3 | Accepted answer
  
  You can manually clear caches with `civicrm_api3('AnyEntity', 'getfields', array('cache_clear' => 1));` (use any valid entity, it doesn't matter which).
  
  However, if you are using the api to create tags, and this does not automatically clear the cached list of tags, I would consider it a bug. If you are able to reproduce it in the latest version please look in the [issue tracker](https://issues.civicrm.org) for an open bug report, and if there isn't one, please open one.
  
  > **Comments:**
  > **username_0**: This worked. We're running 4.4.x. I diffed the tag-related api files between 4.4 and 4.6 and don't see any changes that would suggest the tags cache is cleared or rebuilt after creation.  
  
  ---
  
  ### Answer by username_1 on 2015-04-18. Score: 2
  
  CRM\_Core\_PseudoConstant::flush() should do it.
  
  
  ---
  
  