How to Generate Unique Cache Keys?

I'm trying to improve the performance of my ColdFusion 10 application by making better use of caching.  I have a particular DAO/Gateway CFC that queries a particular database.  I added query caching to the query in this CFC and it made a huge difference.
Since this database is outside my control for edits/updates, I need to be able to initiate flushing of the cached queries for this database only.  I don't believe the built-in ColdFusion ehcache query cache allows for granular control of flushing - in CF Administrator you pretty much can only flush the entire cache.
So I figured the only solution was to create my own cache region that would be associated with just this database, and manually cache the queries into that region.  Then I can flush just that region without impacting any other cached queries.
So here's my difficulty:  I believe that Internally, ColdFusion caches queries using a hash of the generated SQL.  I'm thinking I'll store my queries in cache with a key that hashes the input parameters.  Would the built-in Hash() function be the appropriate mechanism to create cache keys that are unique for each parameter combination?  Does it matter what algorithm I use with Hash()?
Thanks,
-Carl V.

Sorry, didn't see your original question! You might be better asking this on StackOverflow, as there's more people who have more experience with CF keeping an eye on the questions there.
What I can offer is that MD5 hashes are not guaranteed unique for different input strings. It's unlikely to happen, but it can happen. I think - but am not sure - more "thorough" hashing algorithms might be more likely to have a higher degree of uniqueness.
That said, the general approach is how these things are generally done.  And it's very very unlikely that you'll ever come to use a combination of elements contributing to the key that will generate a hash that you've already used for something else.
Adam

Similar Messages

  • Generate Unique Hash Key in PL/SQL

    I have a document that i want to send to certain customers. What I've decided to do is send the customer a link to the document that will be stored locally on our server. Obviously for security reasons i don't want to simply send the sequential doc ID allowing customers to change the query string to get other information.
    What would be the best way in pl/sql to generate a unique hash key to include in the url? The key would have to be both unique and not easily edited by customers to view other documents.
    Any help would be much appreciated.
    Faoilean.

    faoilean wrote:
    I've been experimenting with SHA-1 and it works very well in producing a 40 character hash. My one concern is that for example hashing '1025' produces the following hash 'B74E9CAD775D997FC742B45E1BA7BD5295D63D13'.
    Would someone not just simply be able to use SHA-1 to create a hash for '1026' (since i'm using a sequential number for my input) and consequently retrieve somebody elses information and leave my system vulnerable?
    Might i be better off to encrytp the input?I thought the point was that the "user" would only be provided with the hash value as a reference to the document and they would not have a clue how to alter that hash value to another value in order to retrieve a different document. Surely they don't know that the hash value they have relates to '1025' so a) how would they know that they can obtain the hash for '1026' to get the next document and b) how would they go about creating their own hash values unless you somehow give them access to Oracle's DBMS_CRYPTO package?
    If you really want to be sure then you could also also incorporate the date/time of the document into the string that you hash, so they would have to a) have access to the dbms_crpto package, b) know the filename and the date/time of the document and c) know what order to combine those things (and the format mask you've used on the date/time etc.) to provide the correct hash to obtain the document.
    If you use encryption then you leave yourself open to decryption.
    If you use hash then this is generally a 1 way mechanism, hence details are better hidden.
    I think you'll find when it comes to things like password storage, most will use a 1 way hash (or similar) algorithm rather than an encrypted password so that the stored passwords can never be reverse engineered. Also, such password algorithms usually combine the username or some other feature to prevent two users with the same password getting the same hash value.

  • How to generate unique filenames??

    i need to be able to generate unique files from a servlet..
    my initial instinct was to use the seesion id as part of the filename, however as this file will be embedded in the responding html, this is not safe, as the user will only have to look at the html source to view a session id value.
    i am now considering to use the date/time of the creation of a session as the unique identifier for the file, however this will not work if two sessions can be created at the same time.
    my question thefore is if no two sessions can have the same date and time?
    if not.. can anyone give me an idea as how to produce unique filenames?

    If you are actually creating a file, why not usethe
    java.io.File.createTempFile() method?how does that help with prducing a unique value to use
    as the name of a file?
    with that method i still need to supply the filename
    as one of its arguments!
    No you don't. You provide a prefix and suffix and it fills in the middle with something guaranteed to be unique, in the directory you specify. Here is the javadoc:
    createTempFile
    public static File createTempFile(String prefix,
    String suffix,
    File directory)
    throws IOException
    Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that:
    1. The file denoted by the returned abstract pathname did not exist before this method was invoked, and
    2. Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.
    This method provides only part of a temporary-file facility. To arrange for a file created by this method to be deleted automatically, use the deleteOnExit() method.
    The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail". The suffix argument may be null, in which case the suffix ".tmp" will be used.
    To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved. Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix.
    If the directory argument is null then the system-dependent default temporary-file directory will be used. The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\\temp". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the the temporary directory used by this method.
    Parameters:
    prefix - The prefix string to be used in generating the file's name; must be at least three characters long
    suffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
    directory - The directory in which the file is to be created, or null if the default temporary-file directory is to be used
    Returns:
    An abstract pathname denoting a newly-created empty file
    Throws:
    IllegalArgumentException - If the prefix argument contains fewer than three characters
    IOException - If a file could not be created
    SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not allow a file to be created
    Since:
    1.2

  • How to generate unique numbers

    hi all,
    I want to generate unique numbers always starting from 1 using a single sql query and I dont want to use a sequence and i dont think rownum will be helpful for generating unique numbers in all cases . how to do this ?
    thanks & regards,
    kumar.

    If two users get the MAX from temp, they would be updating with the same value for two different rows.If TEMP is a genuine temporary table, this is not an issue, because the data in a temporary table is only visible within a session.
    The big problem with this approach is the mutating table one: we cannot issue the requisite select statement from a BEFORE INSERT trigger. So this solution is only going to work with a view and an INSTEAD OF INSERT trigger.
    Another, more workable, solution is to use a code control table. This can be (should be) another temporary table, with one row holding one column - next value for TEMP.ID. Normally we would rule out such a solution because it serializes access to the inserted table, but as this is only on a per session basis, it doesn't matter.
    CREATE OR REPLACE TRIGGER tmp_bir BEFORE INSERT ON temp1 FOR EACH ROW
    DECLARE
      ln NUMBER;
    BEGIN
      SELECT nvl(code1.next_id,1) INTO ln
      FROM code1;
      :NEW.id := ln;
      UPDATE code1
      SET    next_id := ln+1;
    END;Beware: coded freehand, so may need debugging.
    Cheers, APC

  • How to generate the primary key item automatically in form region?.

    Hi,
    The primary key item is generated automatically in report region.I already give the pl/sql function for generating of primary key.but I want to generate the primary key value automatically in form region only?.how to do this?.Pls help me..
    Thanks and Regards.

    One of the guidelines when selecting column for a primary key is:
    Choose a column whose data values are never changed. A primary key value is only used to identify a row in the table, and its data should never be used for any other purpose. Therefore, primary key values should rarely or never be changed.
    Cheers!

  • How to generate all possible keys for DES algorithm

    Hello every one,
    I want to generate all the possible key combinations for the DES algorithm 56-bit "actuallly 64 but the last 8 bits are just padding", so can anyone plz help how can i do that? or give me article or something that might help me?
    Thanks in advance,
    Amr M. Kamel.

    I know that but who said that it will be one
    processor it will be on distributed and clustered
    environment :). I just want to know how to generate
    the keys "or write binary".
    Thans again for your helpA cluster of 2285 machines will still take a year! The simplest algorithm is to just count from 0 to 2^56 .
    If you are thinking of cracking DES then there is a Book I have on my shelf 'Cracking DES' published by the 'Electronic Frontier Foundation' ISBN 1-56592-520-3 . It contains the C code and describes the hardware used. The hardware cost was about $100,000 and it cracks DES in about 3.5 days.
    Assuming Moore's law ( http://en.wikipedia.org/wiki/Moore's_law ) applies then it should now take about much less than a day and cost much less than $100,000. BUT - it will take a long time using basic computers.

  • Any easy way to generate unique primary key for database table?

    I'm currently playing with the J2EE reference implementation from Sun which comes with the IBM Cloudscape database. This Cloudscape database supports the use of an AutoIncrement field.
    First question: Can I use CMP and assume that the database will generate a proper key for me? Anyone tried it out successfully before?
    Also, based on what I've heard so far, it seems that generating database primary key is not really well-supported by J2EE using CMP in that a lot of J2EE developers have to resort to workarounds like using a session bean, JDBC and (1) some seed numbers for ID implanted in the database itself (as in the J2EE tutorial DukesBankApp example) or (2) using the SQL MAX aggregation command + 1. Usign seed number is contradictory to good database design and using MAX is dangerous for heavy traffic application if 2 beans try to insert themselves into the database at the same time (synchronizarion problem).
    Anyway I find it dumb that we still have to go back to JDBC and SQL which was the reason why the concept Entity Bean was introduced; to make database persistence transparent! Now it seems that J2EE makes it worse and more troublesome than before.
    Second Question: Is there any easy (hopefully transparent/automatic) way of generating primary key ID?

    if you want to rely on your container or database then go hard, will probably be faster.
    to make a cross container/db soln I used a CMP Entity bean called Sequence with one field for uid
    I use one instance and increment the field each time.
    To do the logic, I have a utils class with static method, no need for session bean overhead
    I reckon this approach is OK considering all things

  • How to generate unique PKIDs to add a new translation

    We need to add a new translation to the table commonXLAExtensionCache. However in the documentation it states:
    -Verify that the pkid that is being inserted is unique per insert. It must start with 1058.
    How can we generate a unique pkid, is there a database command.
    For this example, we are adding a new translation for a custom FlexSync report are using.

    MSSQL DB
    select '1058' + upper(newid());
    Oracle DB
    select ('1058' || newid) from dual;

  • How to generate unique IDs for a metadata field

    Hi,
    We have a requirement to generate a unique ID for a metadata field. Does anybody know how this can be achieved? Ideally I would want to have a database sequence and specify the metadata field to get value from this database sequence, similar to how Content ID is generated.
    Any help is appreciated. Thank you in advance.
    Regards,
    Tim

    Look into the Counters table. You should be able to create a component install filter to add in your field to the Counters table.
    You could then create some Java code to fetch the next value from the Counters database for your field (and increment the value).
    Jonathan
    http://redstonecontentsolutions.com
    http://corecontentonly.com

  • How to Generate   Unique Serial No in Oracle 6i report

    Hi
    I want to generate a unique serial no for every row ,
    how can i achieve this result.
    thanx in advance

    You can also use the analytical function ROW_NUMBER in your query
    SELECT ...
               ROW_NUMBER() OVER (ORDER BY YOURORDERBY) RN
      FROM TABLE
    ORDER BY RN;

  • How to generate Unique Seq Id in BPEL

    Hi All,
    How can we generate a unique seq Id in BPEL.
    One way is to use "*orcl:generate-guid()*" .
    Are there any other ways by which we can generate the unique seq id. please send me some sample piece of code if any for example.
    Regards
    Narendra
    Mail to: [email protected]

    Probably not best practice, but I created a sequence in one of my Oracle DBs to call and get a unique ID. You could do something similar with a call to a SQL DB. If you don't care if it is a number or not you could use the Generate GUID function within BPEL.
    --S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to enforce unique primary key constraint in xsd

    Hi,
    I'm trying to enforce primary key constraint in xsd. I'm using the following xsd to generate the xmls .
    <?xml version="1.0" encoding="UTF-8"?>
    <!--<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault=
    "unqualified">-->
    <xs:schema targetNamespace="http://TBD-URI" elementFormDefault="qualified"
    attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="Employees">
                <xs:annotation>
                      <xs:documentation>Contains All Employee information</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                      <xs:sequence>
                            <xs:element name="Employee" maxOccurs="unbounded">
                                  <xs:complexType>
                                        <xs:sequence>
                                              <xs:element name="Empno" type="xs:int" />
                                              <xs:element name="Ename" type="xs:string" />
                                              <xs:element name="Sal" type="xs:float" />
                                              <xs:element name="Deptno" type="xs:int" />
                                        </xs:sequence>
                                  </xs:complexType>
                            </xs:element>
                      </xs:sequence>
                </xs:complexType>
                <xs:key name="PK_Employee_Empno">
                      <xs:selector xpath=".//Employee" />
                      <xs:field xpath="Empno" />
                </xs:key>
          </xs:element>
    </xs:schema>Here's the generated XML
    <?xml version="1.0" encoding="UTF-8"?>
    <Employees xmlns="http://TBD-URI"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://TBD-URI file:/C:/Documents%20and%20Settings/ctsuser/workspace/JAXB/src/test/resources/TEST.xsd">
        <Employee>
            <Empno>0</Empno>
            <Ename>Ename0</Ename>
            <Sal>0</Sal>
            <Deptno>0</Deptno>
        </Employee>
        <Employee>
            <Empno>0</Empno>
            <Ename>Ename1</Ename>
            <Sal>0</Sal>
            <Deptno>0</Deptno>
        </Employee>
    </Employees>The generated XML allow the same Empno on which the primary key constraint has been defined. I'll appreciate if someone can provide pointers on how to enforce this constraint so that it doesn't allow the same Empno to be repeated.
    Thanks

    Could you please append your solution?
    There is a chance that someone in the future may have a similar problem, and might find this entry. As the entry exists now, all they will find out is that you solved it -- which does not help them at all.

  • How to generate unique values while initializing values

    I am initializing values in my pl/sql program and want to use a sequence to set my unique ids but it errors out. Below is what I use.
    ie. table_id := table_seq.nextval;
    How can I use my sequence to initialize values or is this possible?

    The method suggested by user605919 will work. However, you don't need to initialize a variable like this. It is better and more performant to do it like the third example below:
    SQL> create table mytable
      2  ( id number(6)
      3  , description varchar2(30)
      4  )
      5  /
    Tabel is aangemaakt.
    SQL> create sequence table_seq start with 1 increment by 1
      2  /
    Reeks is aangemaakt.
    SQL> declare
      2    table_id mytable.id%type := table_seq.nextval;
      3  begin
      4    insert into mytable
      5    ( id
      6    , description
      7    )
      8    values
      9    ( table_id
    10    , 'Some description'
    11    );
    12  end;
    13  /
      table_id mytable.id%type := table_seq.nextval;
    FOUT in regel 2:
    .ORA-06550: line 2, column 41:
    PLS-00357: Table,View Or Sequence reference 'TABLE_SEQ.NEXTVAL' not allowed in this context
    ORA-06550: line 2, column 12:
    PL/SQL: Item ignored
    ORA-06550: line 9, column 5:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 9, column 5:
    PL/SQL: ORA-00904: "TABLE_ID": invalid identifier
    ORA-06550: line 4, column 3:
    PL/SQL: SQL Statement ignored
    SQL> declare
      2    table_id mytable.id%type;
      3  begin
      4    select table_seq.nextval
      5      into table_id
      6      from dual
      7    ;
      8    insert into mytable
      9    ( id
    10    , description
    11    )
    12    values
    13    ( table_id
    14    , 'Some description'
    15    );
    16  end;
    17  /
    PL/SQL-procedure is geslaagd.
    SQL> begin
      2    insert into mytable
      3    ( id
      4    , description
      5    )
      6    values
      7    ( table_seq.nextval
      8    , 'Some description'
      9    );
    10  end;
    11  /
    PL/SQL-procedure is geslaagd.And if you need the id value for some code after the insert, you use the RETURNING clause.
    Regards,
    Rob.

  • How to generate unique random numbers

    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
      int roll = diceRoller.nextInt(6) + 1;
      System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.
    Many thanks,
    Jack

    htran_888 wrote:
    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
    int roll = diceRoller.nextInt(6) + 1;
    System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.If it is your school assignment then you have the answer above (List & the lists length).
    (You might want to look at Collections)

  • How to generate unique document number ?

    Hi All,
    We need to generate Document Number where there should be any gap, so that we cannot use sequence. For example : Invoice Number.
    one possible approach like : Select MAX(InvoiceNumber)+1 from invoice, what if that table has millions of rows, is this reliable enough ?
    How to avoid two user do the same query at same time that lead to dupplicate number ?
    Anybody has done it this way in production? or any other approach ?
    Thank you for your info,
    xtanto

    I strongly second Justin's strong suggestion about re-considering the requirement.
    Be aware that for any of the schemes suggested to have a chance of working, all access to the table must be through stored procedures that use a SELECT FOR UPDATE on the counter table. No user in the database can have insert privileges on the document table except the owner. The owner's password should be kept in a locked safe and be unknown to anyone. If for some reason the owner needs access to the database, then remove the password from the safe, do what needs to be done, then get some guy off the street to set a new password, write it down and lock it in the safe again.
    If you really need a gap-free number, it needsto be another column, separate from the PK. Use a sequence to generate the pk gaps and all, then create a procedure that runs periodically to update the gap free column. Soemthing like:
    SQL> CREATE PROCEDURE fix_gap_free AS
      2     l_v NUMBER;
      3     TYPE id_tbl IS TABLE OF number INDEX BY BINARY_INTEGER;
      4     l_ids  id_tbl;
      5     l_id2s id_tbl;
      6  BEGIN
      7     SELECT MAX(NVL(id2,0)) INTO l_v FROM t;
      8     SELECT id, ROW_NUMBER() OVER (ORDER BY id)
      9     BULK COLLECT INTO l_ids, l_id2s
    10     FROM t
    11     WHERE id2 IS NULL;
    12
    13     FORALL i IN 1 .. l_ids.COUNT
    14        UPDATE t
    15        SET id2 = l_id2s(i) + l_v
    16        WHERE id = l_ids(i);
    17     COMMIT;
    18  END;
    19  /
    Procedure created.
    SQL> SELECT * FROM t;
            ID        ID2
             1
             2
             5
             7So, id2 is going to be the gap-free column.
    SQL> exec fix_gap_free;
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM t;
            ID        ID2
             1          1
             2          2
             5          3
             7          4So first pass is fine. Now lets add a few rows, so the table now looks like:
    SQL> SELECT * FROM t;
            ID        ID2
             1          1
             2          2
             5          3
             7          4
             8
             9
            25and generate more gap free number:
    SQL> exec fix_gap_free;
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM t;
            ID        ID2
             1          1
             2          2
             5          3
             7          4
             8          5
             9          6
            25          7If there may be deletions in the table, and you need to maintain the gap free nature, then just skip the WHERE id2 IS NULL predicate.
    John

Maybe you are looking for

  • Dhcdbd no longer available.

    Howdy, I've noticed that the package dhcdbd is no longer available in the repo's. Is this something I should leave installed or should I remove it? I know there was a recent upgrade to network-manager, has this effectively taken over what dhcdbd did?

  • Im stumped with loading an id number into flash.

    I have a flash file (actionscript 2) created that calls an external text file, and loads it into a scrolling text area. example: // send and load variables lv.load(" http://website.com/" + id + ".txt"); the url i want to load looks like this: http://

  • Files in watch folder not moving to "Sources" after being processed

    Files are not moving from the root of the watch folder into the "Sources" folder after being processed, which results in the files getting re-processed everytime AME is re-opened. I just upgraded to Creative Cloud from the Production Bundle 5.5 with

  • Imac slow performance after upgrade to 10.10.2

    Following the installation of 10.10.2, my imac (circa 2010) is super slow to launch apps and in general just is under performing. A security update seems to be installed every time I reboot.. has anyone seen similar behavior? Tips ? Thanks !

  • How to schedule multiple wakes up with Terminal

    Hello, I would like to schedule mutliple wakes up for my iMac, in order to keep the network connection, because after 6 hours of innactivity, it disconnects. I've read that I could type: pmset [repeat] [wake] [<MTWRFSU> <6:00:00>] That way, eveyday a