Answers.Body: <p>With a timeout setting of 0 for the smart group cache, Civi was none-the-less working with a timeout of 5 minutes. When a contact is added, clearContactCaches() is called which does call CRM_Contact_BAO_GroupContactCache::remove(). However smart groups that have not timed out will not be cleared.</p>
  
  <p>To fix my issue I added to clearContactCaches() a call to clear the specific group that might be used immediately, ie:
  CRM_Contact_BAO_GroupContactCache::remove(1234);</p>
  
  <p>I also found a bug in GroupContactCache.php in 4.6.18, reported here:
  <a href="https://issues.civicrm.org/jira/browse/CRM-19005" rel="nofollow">https://issues.civicrm.org/jira/browse/CRM-19005</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-24T17:25:01.540Z
Answers.LastActivityDate: 2016-06-24T17:25:01.540Z
Answers.UserDisplayName: chriscant
Answers.Body: <p>Experienced the same problem...with 4.6.18</p>
  
  <p>Went hunting through CiviCRM's JIRA issue tracker and found many interrelated issues surrounding smart group cache problems for 4.6</p>
  
  <p>Look here and make the changes: 
  <a href="https://github.com/civicrm/civicrm-core/pull/6694/files" rel="nofollow">https://github.com/civicrm/civicrm-core/pull/6694/files</a></p>
  
  <p>The patch won't apply cleanly, but you can figure out where to make the 2 line change....</p>
  
  <p>Also did the changes in this commit for good measure:
  <a href="https://github.com/civicrm/civicrm-core/pull/8637/commits/189d2597929fc6d39f2f587ec5696f74b0ea8775" rel="nofollow">https://github.com/civicrm/civicrm-core/pull/8637/commits/189d2597929fc6d39f2f587ec5696f74b0ea8775</a></p>
  
  <p>Boom, immediately smart groups started to respond immediately</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-04T18:12:52.750Z
Answers.LastActivityDate: 2016-08-04T18:12:52.750Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>We are on 4.6.18 and Drupal. The code in CRM\Contact\BAO\GroupContactCache.php has updated since 4.6.17.</p>
  
  <p>We have users joining our public site to get a Drupal username and a CiviCRM membership (having paid a contribution). They then have a link to view and update their profile. When new users click to view their profile, they see "Permission Denied You do not have permission to view this contact record. Contact the site administrator if you need assistance." </p>
  
  <p>From looking at the code, this message appears if the contact is not in the profile's group. The CiviCRM profile does indeed Limit listing to a specific group, which is a smart group with contacts with the relevant membership types.  Our smart group timeout is zero so it should update immediately. However this seems not now to be happening. If I "Cleanup Caches" then the contact is put in the group and it works fine.</p>
  
  <p>I haven't got detailed evidence but it seemed like our smart group cache was never updating.</p>
  
  <p>I could set the cache timeout and set up a scheduled task to rebuild the smart group cache. However this would not be ideal.</p>
  
  <p>I haven't looked at GroupContactCache.php
  Has the above behaviour changed in recently?
  How can I fix this?
  Or any other suggestions on how to avoid this problem?</p>
  
  <p>Thanks, Chris</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-23T21:05:37.560Z
Comments.Text: At the moment, the smart groups aren't rebuilt even if I set up a scheduled task and give the cache a non-zero timeout. Help!
Comments.UserDisplayName: chriscant
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-24T15:20:54.570Z
Comments.Text: Part of the problem is that the new GroupContactCache.php incorrectly uses Ymdhis instead of YmdHis twice near the end. However this doesn't solve my problem.  I'll file a bug report for this in due course.
Comments.UserDisplayName: chriscant
Tags: <smartgroups>
Title: Smart group cache not updating with timeout of 0
ThreadText: # Smart group cache not updating with timeout of 0
  
  (Asked by: username_0 on 2016-06-23)
  
  We are on 4.6.18 and Drupal. The code in CRM\Contact\BAO\GroupContactCache.php has updated since 4.6.17.
  
  We have users joining our public site to get a Drupal username and a CiviCRM membership (having paid a contribution). They then have a link to view and update their profile. When new users click to view their profile, they see "Permission Denied You do not have permission to view this contact record. Contact the site administrator if you need assistance."
  
  From looking at the code, this message appears if the contact is not in the profile's group. The CiviCRM profile does indeed Limit listing to a specific group, which is a smart group with contacts with the relevant membership types. Our smart group timeout is zero so it should update immediately. However this seems not now to be happening. If I "Cleanup Caches" then the contact is put in the group and it works fine.
  
  I haven't got detailed evidence but it seemed like our smart group cache was never updating.
  
  I could set the cache timeout and set up a scheduled task to rebuild the smart group cache. However this would not be ideal.
  
  I haven't looked at GroupContactCache.php
  Has the above behaviour changed in recently?
  How can I fix this?
  Or any other suggestions on how to avoid this problem?
  
  Thanks, Chris
  
  **Tags:** smartgroups
  
  > **Comments:**
  > **username_0**: At the moment, the smart groups aren't rebuilt even if I set up a scheduled task and give the cache a non-zero timeout. Help!  
  > **username_0**: Part of the problem is that the new GroupContactCache.php incorrectly uses Ymdhis instead of YmdHis twice near the end. However this doesn't solve my problem.  I'll file a bug report for this in due course.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2016-06-24. Score: 1
  
  With a timeout setting of 0 for the smart group cache, Civi was none-the-less working with a timeout of 5 minutes. When a contact is added, clearContactCaches() is called which does call CRM\_Contact\_BAO\_GroupContactCache::remove(). However smart groups that have not timed out will not be cleared.
  
  To fix my issue I added to clearContactCaches() a call to clear the specific group that might be used immediately, ie:
  CRM\_Contact\_BAO\_GroupContactCache::remove(1234);
  
  I also found a bug in GroupContactCache.php in 4.6.18, reported here:
  <https://issues.civicrm.org/jira/browse/CRM-19005>
  
  
  ---
  
  ### Answer by username_1 on 2016-08-04. Score: 0
  
  Experienced the same problem...with 4.6.18
  
  Went hunting through CiviCRM's JIRA issue tracker and found many interrelated issues surrounding smart group cache problems for 4.6
  
  Look here and make the changes:
  <https://github.com/civicrm/civicrm-core/pull/6694/files>
  
  The patch won't apply cleanly, but you can figure out where to make the 2 line change....
  
  Also did the changes in this commit for good measure:
  <https://github.com/civicrm/civicrm-core/pull/8637/commits/189d2597929fc6d39f2f587ec5696f74b0ea8775>
  
  Boom, immediately smart groups started to respond immediately
  
  
  ---
  
  