I have a webservice that stores an authenticated users token in the HttpRuntime.Cache to be used on all subsequent requests. The cached item has a sliding expiration on it of 24 hours.
Secondly I have a vb.net app that is pinging this webservice every 15 seconds. It gets authenticated once, then uses the cached token for all subsequent requests. My problem is that the application appears to lose authentication at random intervals of time less than the 24 hr sliding expiration. However with it getting pinged every 15 sec the authentication should never expire.
I am looking for a way to view the HttpRuntime.cache to try and determine if the problem is in the webservice security methods or within the vb.net app. Can I view the HttpRuntime.cache somehow?
The webservice is part of a web forms site that was built with asp.net 2.0 on a Windows Server 2008.
The name of my key's were unknown as they were system generated guid values with a username as the value. So in order to view a cache collection that was unknown I used a simple loop as follows.
Dim CacheEnum As IDictionaryEnumerator = Cache.GetEnumerator()
While CacheEnum.MoveNext()
Dim cacheItem As String = Server.HtmlEncode(CacheEnum.Entry.Key.ToString())
Dim cacheItem2 As String = Server.HtmlEncode(CacheEnum.Entry.Value.ToString())
Response.Write(cacheItem & ":" & cacheItem2 & "<br />")
End While
Hope this helps others.
First off, HttpRuntime.Cache would not be the best place to store user authentication information. You should instead use HttpContext.Current.Session to store such data. Technically the cache is allowed to "pop" things in it at its own will (whenever it decides to).
If you actually need to use the cache, you can check if your item is in the cache by simply doing:
HttpRuntime.Cache["Key"] == null
Related
I am using AWS S3 with Rails 7 to store images via Active Storage. I'm presenting my data to the view by querying Elasticsearch (using the elasticsearch-model gem).
While this works great for my other data, the expiration of the signed AWS URL becomes an issue after a little while and the images are of course no longer accessible.
class MyClass
has_one_attached :image
end
I'd like to be able to have a fresh URL and still use Elasticsearch so that I don't need to make a trip to the database every time I want to see the image.
I have looked up whether I can just remove the expiration however I've read that it's unsafe and mostly unsupported. I know that Elasticsearch::Model callbacks exists but I'm not clear on whether that could be applied to ActiveStorage::Blob, especially since nothing changes in the DB when the expiration occurs.
I've also thought about just changing the URLs to expire at 1 week via passing in the expires_in param to the url method on the attachement and then performing a chon job to update the image once a week. Seems hacky though.
I'm sure there are many ways to approach this but what worked for me was using the save callback on an async job when the model that contains the Elasticsearch::Model. When this particular attribute was updated, I called a job with a delay just before the maximum signed_url time allowed by s3 which is 7 days.
after_save :set_refresh_url_job, if: Proc.new { logo_url? }
def set_refresh_url_job
RefreshLogoUrlJob.
set(wait: MyModel::LOGO_EXPIRTY_REFRESH).
perform_later(self)
end
I'm working on a simple script in a custom theme in Drupal 7 that is supposed to just rotate through different background image each time a user loads the page. This is my code in [view].tpl.php that picks which image to use.
$img_index = (!isset($_SESSION["img_index"]) || is_null($_SESSION["img_index"])) ? 1 : $_SESSION["img_index"] + 1;
if ($img_index > 2) {
$img_index = 0;
}
$_SESSION["img_index"] = $img_index;
Pretty simple stuff, and it works fine as long as Drupal starts up a session. However, if I delete my session cookie, then always shows the same image, a session is never started.
I'm assuming that since this code is in the view file that the view code is being cached for anonymous users and hence the session is never started, but I can't figure out how to otherwise do what I want.
Don't mess with session like /u/maiznieks mentioned on Reddit. It's going to affect performance.
I've had to do something similar in the past and went with an approach like /u/maiznieks mentions. It's something like this,
Return all the URLs in an array via JS on Drupal.settings.
Check if a cookie is set.
If it's not, set it and set it's value to 0.
If it's set, get the value, increase the value by one, save it to the cookie.
With that value, now you have an index.
Check if image[index] exists
If it does, show that to the user.
If it doesn't, reset index to 0 and show that. Save 0 to the cookie.
You keep caching. You keep showing the user new images on every page load.
You could set your current view to do a random sort every 5 mins. You would then only have to update the logic above to replace that image. That way you can keep something similar working for users with no JS but still keep this functionality for the rest.
You can replace cookies above with HTML5 local storage if you'd like.
#hobberwickey, I will suggest to create a custom module and implement hook_boot() in module. As per drupal bootstrap process session layer will call after cache layer everytime. hook_boot can be called in cache pages and before bootstrap process also. You can take more information here.
I am trying to implement session management, where we store jwt token to redis. Now I want remove the key if the object idle time is more than 8 hours. Pls help
There is no good reason that comes to my mind for using IDLETIME instead of using the much simpler pattern of issuing a GET followed by an EXPIRE apart from very trivial memory requirements for key expiry.
Recommended Way: GET and EXPIRE
GET the key you want.
Issue an EXPIRE <key> 28800.
Way using OBJECT IDLETIME, DEL and some application logic:
GET the key you want.
Call OBJECT IDLETIME <key>.
Check in your application code if the idletime > 8h.
If condition 3 is met, then issue a DEL command.
The second way is more cumbersome and introduces network latency since you need three round trips to your redis server while the first solution just does it in one round trip if you use a pipeline or two round trips without any app server time at worst.
This is what I did using Jedis. I am fetching 1000 records at a time. You can add a loop to fetch all records in a batch.
Jedis jedis = new Jedis("addURLHere");
ScanParams scanParams = new ScanParams().count(1000);
ScanResult<String> scanResult = jedis.scan(ScanParams.SCAN_POINTER_START, scanParams);
List<String> result = scanResult.getResult();
result.stream().forEach((key) -> {
if (jedis.objectIdletime(key) > 8 * 60 * 60) { // more than 5 days
//your functionality here
}
});`
We are using Kaltura to notify our CMS about changes in the videos. In the KMC under Settings->Integrations Settings we have checked all the checkboxes under "Sent by Server".
Some times these checkmarks disappear? IT happens maybe once a week or once a month. How can we find the reason to these boxes being deactivated?
Those notifications are being stored on the partner object in partner table. The actual data is stored in the custom_data field, which holds large amount of PHP-serialized data.
I can suspect cases that due to updates of other fields in the custom_data object, the notifications section will be erased.
Your best shot would be first check the value of that field when the config got erased. If it was actually erased in the database, try to find the following log messages in api_v3.log (which can lead you to the actual API request that modified the field):
[2124167851][propel] */ UPDATE partner SET
`UPDATED_AT`='2017-10-04 14:11:36',
`NOTIFY`='1',
`CUSTOM_DATA`='a:79:{s:9:"firstName";s:5:"Roman";s:12:"isFirstLogin";b:0;
... tons of PHP serialized data ...
i:1;s:19:"notificationsConfig";s:42:"*=0;1=1;2=1;3=1;4=0;21=0;6=0;7=0;26=0;5=0;";
... tons of PHP serialized data ...
}' WHERE partner.ID='101' AND MD5(cast(partner.CUSTOM_DATA as char character set latin1)) = '7eb7781cc04c7f98077efc2e3c1e9426'
The key that stores the notifications config is notificationsConfig (Each number represents the notification type, then 0 / 1 for off / no).
As a side note, which CE version are you using? There might be a more reliable way to integrate with your CMS.
Scenario:
I am working with IIS and ASP, and we need to cache the site (to make Google Page Speed, and my boss, happy). We currently have IIS caching everything (asp/JS/CSS) for a period of 1 week.
Problem:
After updating the HTML content on the ASP pages, my boss sees the old version of the page until he does a (force) refresh.
Question:
How can I (force) update the server cache after I make a change to the ASP HTML content?
I would like my peers and managers to see the latest changes without making them do a forced browser refresh.
Are you configured to use the "If-Modified-Since" HTTP Header?
This explanation on Scott Hanselman's blog gives you and idea of what you are looking for - Forcing an update of a cached JavaScript file in IIS
This page also provides a useful primer for the "If-Modified-Since" HTTP Header
Let's see if we can make the boss happy. Like you, I have a few people that think F5 or Ctrl+F5 is annoying.
Quick Review, to be sure your Output Cache on your IIS server is updating on Change let's set it to "Cache until Change".
I read that you clear it every week but if things don't change... Why?
Let's set the client browser caching defaults.
And you have the following for all your page headers letting the page expire after 30 minutes using GMT time.
Master header:
Dim dtmExp
Response.Buffer = True
Response.CharSet = "UTF-8"
dtmExp = DateAdd("n", 30, Now())
Response.ExpiresAbsolute = dtmExp
Response.Expires = dtmExp
We have several options and methods to trigger our header change.
You can use Sessions, Cookies, DB updates etc. in this example I'm using Sessions feel free to change things around to fit your application better.
PageEdit.asp
Session("EditedPageFullURL") = "/yourpage.asp"
In a common functions page add the following.
Function EditorsReload(eChk,erURL)
If IsNumeric(eChk) Then
Session("Editing") = eChk
End If
If Len(erURL) = 0 Then
Exit Function
End If
If Session("Editing") <> "" Then
If Session("Editing") = 1 Then
If (LCase(erURL) = LCase(Request.ServerVariables("SCRIPT_NAME"))) Then
Session("Editing") = ""
Session("EditedPageFullURL") = ""
Response.Expires = -1
Response.ExpiresAbsolute = Now() -1
Response.AddHeader "pragma", "no-store"
Response.AddHeader "cache-control","no-store, no-cache, must-revalidate"
End If
End If
End If
End Function
Place the following in your page just below any headers you might have.
Call EditorsReload(1,Session("EditedPageFullURL"))
You can wrap it in a "Session("AUTH")" if your site has login and member sessions setup.
Other than that, this will fire only when Session("EditedPageFullRUL" has a length greater than 1.
This will update the bosses browser header forcing the browser to refresh the local cache.
It is a one time deal so any additional page refresh is using the standard headers.
There are many ways of doing this so be creative!