Coldfusion session variables usage - coldfusion

I have few doubts on coldfusion session scope variables usage.
I am using Jquery calendar to show the daily/scheduled events per monthly basis. The event detail rows(json records) are saved in cfm array variable, when user click on next/previous month it is going to make an ajax call and will be getting a new cfm array variable with required event records. Initially I tried to store the previous search events array in browser localstorage but unable to do it properly as the size of array exceeds 8MB and the browser limit should be below 5MB(in chrome, it varies based on browsers), even though using compress technique also having issues in IE browser, finally I want to save the last 6 cfm arrays(earlier search events data) in session scope and at the time of saving 7th array I deleted the first events array. Please suggest whether we can proceed this or is there any other scope like client rather than session scope. I am working in coldfusion 9 environment.

Related

iCloud records only seen when directly searched

If I go to the iCloud dashboard and search (Filter:) for a record by exact recordName, the record is found. However, if I search using any range or inexact methods (i.e. search by date range etc.), the record is not found. Also, the record is not returned inside my Objective C program when I query all records of that type. It appears to be random records that have this characteristic. I recently inserted 40 or more records of this type (via software) and this behavior is only seen in 6 of them. I have tried using the dashboard to update the affected records, in hopes that this might trigger "update" events on the backend. Nothing that I have tried fixes this!!
I should add that my data is in the Development environment, not Production.
I may have found a work around for this problem. In the iCloud dashboard, I deleted the index QUERYABLE on the recordName field (the only index on this field) and then added it back. I then waited about 5 minutes or so and this seemed to fix the problem. However, I believe that this is, perhaps, a bug in the backend iCloud server.

Ember Substates with Ember data after store already has data

I have read Ember docs related to Substates etc and I understand how it works. In my current application my loading.hbs and other child loading.hbs templates work fine.
I just want to discuss a use case.
In my route A, in my model function I do fetchAll for my model.
I go to Route A, First time api request is sent and I see my loading screen.
now I navigate to some other route B.
now I come back to first route A, api request is sent again but this
time loading screen is not shown.
I want to develop my understanding here. Now the second time loading screen is not shown which tells us that store had data so there is no sense to put it on loading and after fetch store sent request to sync with backend.
QUESTION
Now I want to know if this is a default behaviour of Ember with Ember-data?
To show this loading screen, will I have to do something manually?
Ideally what I want is, if on second request data was fetched then show it and at the same time show loader to tell user that it is syncing with backend as well.
I know everything can be done manually, I don't want to reinvent the wheel or do things in non-conventional way. So I want to know best optimized solution for this as provided by Ember which an experienced Ember developer can help me understand.
Thanks in advance.
Now I want to know if this is a default behaviour of Ember with
Ember-data?
Yes, that's the default behavior of Ember data when you do a findRecord or findAll where shouldBackgroundReloadRecord or shouldBackgroundReloadAll event of the adapter respectively, is defaulted to true. You can turn this off by returning false and ensuring shouldReloadAll or shouldReloadRecord respectively are set at true to ensure the request always hits the API and not fetches from cache.
Ideally, showing data immediately on the screen is always advisable as it has a better UX in terms of giving the user a feel that data is already there and that some parts of the data is being fetched. Check here
To show this loading screen, will I have to do something manually?
You may also want to read this
To add further details after my own research, I found helpful and relevant details in Ember docs.This is all about caching.
If records were already there then promise will be resolved immediately that's why I don't see loading screen for already loaded record, at the same time Ember-Data syncs with backend as well and re-render the template.
Ember Model Docs
Caching
The store will automatically cache records for you. If a record had already been loaded, asking for it a second time will always return the same object instance. This minimizes the number of round-trips to the server, and allows your application to render its UI to the user as fast as possible.
For example, the first time your application asks the store for a person record with an ID of 1, it will fetch that information from your server.
However, the next time your app asks for a person with ID 1, the store will notice that it had already retrieved and cached that information from the server. Instead of sending another request for the same information, it will give your application the same record it had provided it the first time. This feature—always returning the same record object, no matter how many times you look it up—is sometimes called an identity map.
Using an identity map is important because it ensures that changes you make in one part of your UI are propagated to other parts of the UI. It also means that you don't have to manually keep records in sync—you can ask for a record by ID and not have to worry about whether other parts of your application have already asked for and loaded it.
One downside to returning a cached record is you may find the state of the data has changed since it was first loaded into the store's identity map. In order to prevent this stale data from being a problem for long, Ember Data will automatically make a request in the background each time a cached record is returned from the store. When the new data comes in, the record is updated, and if there have been changes to the record since the initial render, the template is re-rendered with the new information.

Is there a "ThisVisit" timestamp in ColdFusion?

Coldfusion has a system created client variable called lastvisit.
Is there a way to get the value of that variable during the request that it is actually set (i.e. client.thisvisit)?
The idea would be that I can store the "ThisVisit" timestamp in session and then compare it to lastvisit when the next request is made. This would tell me if another request was made in the session.
The purpose is that we have a page that we use an ajax record lock on which refreshes the lock every minute. After sixty minutes the ajax lock code will automatically log the user out of the website (due to inactivity). The issue arises where the user is executing tasks in other windows/tabs (indication of activity).
Sense all requests update LastVisit, I would like to have the ajax lock code save the save a "thisvisit" value so that the next time it runs it can compare it to the LastVisit client variable.
A couple requirements:
Set up to use a DB rather than registry for your client vars (trust
me).
Client vars have to have "global variables" enabled
Your cfapplication or application.cfc has to have client management enabled.
If you have those three things you can select a query like the following:
<cfquery name="getLvisit" datasource="myClientVarsDB">
SELECT lvist
FROM cglobal
WHERE cfid =
<cfqueryparam type="CF_SQL_CHAR" value="#urltoken#"/>
</cfquery>
urltoken might be wrong... it may need the jsessionID or CFID but my memory tells me cftoken. I'd have to hunt down a site using Client DBs to give you a definitive answer.
So that would give you the current value of the lvisit variable. you would store this in the session and then compare it against the value from the table on subsequent queries before you overwrite it again (if that makes sense).
Note - this value is updated on each request - so your query get's the current value (before it has been updated). I previously thought this it was updated first but according to Tom it's actually updated last.

Keep value state in apex page

Does anyone know to keep the state in an apex page when I go to another page and return?. It doesn't keep the values entered in the fields, it appears all empty. I appreciate anyone can help. Thanks
What is your ApEx version ?
By default, when you submit a page, item values are automatically set in session state, so you should find them again when you go back to the page.
Be aware that Firefox retain form element values on page refresh, so displayed values may not correspond to values that are really in session state... A solution is to set the «Form Auto Complete» attribute to "Off" in your page security attributes, or use $('#wwvFlowForm').attr('autocomplete','off'); on page load.
If you want to set a value into session state manually without submitting the page :
from PL/SQL, you can use APEX_UTIL.SET_SESSION_STATE (see documentation)
from JavaScript, you have to call a dummy application process, like :
setItemInSessionState: function(p_item, p_value) {
var l_get = new htmldb_Get(null,$('#pFlowId').val(),'APPLICATION_PROCESS=dummy',0);
l_get.add(p_item, p_value);
l_get.get();
}
Finally you can choose to maintain session state per session, or for a user across sessions, by changing «Maintain session state» attribute in the source tab of your item. And if your data is sensitive, you can set «Session State Protection» attribute to "Yes" for your item.
There are a lot of other solutions to keep item values between pages : passing values in the URL into hidden items, apex collections, basic database storage, cookies, etc.
If this does not answer your question, you might give more details.
Maybe you should use session in order to save the inputs and then when the client returns to that page, you will just put the data you have stored in the sessions.

accurate page view count in Django

What is a good approach to keeping accurate counts of how many times a page has been viewed?
I'm using Django. Specifically, I don't want refreshing the page to up the count.
As far as I'm aware, no browsers out there at the moment send any kind of message/header to the server saying whether the request was from a refresh or not.
The only way I can see to not count a user refreshing the page is to track the IPs and times that a user views a page, and then if the user last viewed the page less than 30 minutes ago, say, you would dismiss it as a refresh and not increment the page view count.
IMO most page refreshes should be counted as a page view anyway, as the only reason I have for refreshing is to see new data that might have been added, or the occasional accidental refresh/reloading after a browser crash (which the above method would dismiss).
You could give each user cookie, that expires at the end of the day, containing a unique number. If he reloads a page you can check wether she has been counted already that day.
You could create a table with unique visitors of the pages, e.g. VisitorIP + X-Forwarded-For content, User-Agent string along with a PageID of some sorts. If the data itself is irrelevant, you can create a md5/sha1 hash from these values (besides the PageID of course). Be warned however that this table will grow really fast.
I'd advise against setting cookies for that purpose. They have a limited size and with many visited pages by the user, you could reach that limit and make the solution unreliable. Also it makes it harder to cache such page on client-side (see Cacheability), since it becomes interactive content.
You can write a django middleware and catch request.url, then setup a table with url / accesses columns. Beware of transactions for concurrent update.
If you have load problems, you can use memcached with incr or add function and periodicaly update the database table to avoid transaction locks.