Duplicate Cache PDFs Created When Loading Document from API or Query
Problem reported by Kavindu Shavinda - 9/25/2025 at 2:55 AM
Resolved

Hi,

I am using GleamTech DocumentUltimate (7.6.6).

I have implemented a custom Document Viewer setup where a file can be loaded from a static file path, an API, or a SQL query.
  • When I load a document from a static file path, the file is displayed correctly and caching works as expected.

  • However, when I load the document from an API or a SQL query, I notice that two cache PDFs are created in the cache location. These duplicate cache files are not created when using the static file path option.

Is this the expected behavior when using API or query-based document loading? If not, how can I avoid duplicate cache PDFs from being generated?

Thank You.

Cem Alacayir Replied
Employee Post Marked As Resolution
This looks like the result of keepVariations  or  CacheKeepVariations

keepVariations  Boolean  (Optional)
Whether to keep variations of document conversion results. The default is false.

For instance when you change watermark options, both Pdf and Xpz outputs are regenerated. By default the Pdf and Xpz outputs are replaced in cache when watermarks are changed. If you set this property to true, the Pdf and Xpz outputs will not be replaced but all variations will be kept in cache instead. This can be useful especially when you want different outputs for different users. So this way, for instance you can have different watermarked variations for each different user.

So if you are creating DocumentCache in your API server directly, maybe you are passing a different value for this parameter (default value is actually false for DocumentCache or DocumentUltimateWebConfiguration).
Kavindu Shavinda Replied
In my case, I have not configured those properties anywhere, so I don’t think they are causing the duplicate cache files. I suspect it might be related to my custom handler implementation. 

I recently upgraded DocumentUltimate from v6.2.1 to v7.6.6. In the older version (6.2.1), my custom handler implementation worked fine and I did not see duplicate cache PDFs being generated. After upgrading to 7.6.6, I had to refactor some code because a few internal classes changed, and now I’m noticing this caching behavior.

public override string File
        {
            get;
            set;
        }

        public override bool CanGetInfo => true;

        public override bool CanOpenRead => true;

        public override bool CanOpenWrite => false;

        public override bool CanSerialize => false;

        protected override FileProviderInfo DoGetInfo()
        {
            byte[] fileContent = new byte[0];
            DateTime lastModified = DateTime.UtcNow;

            string sql = string.Format(selectCommand, parentKey);
            var dataSet = DataServiceBase.ExecuteDataset(connectionString, CommandType.Text, sql);
            if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
            {
                if (isFileNameMapped)
                {
                    this.File = dataSet.Tables[0].Rows[0][fileName].ToString();
                }
                 
                if (mustBase64Decode)
                {
                    fileContent = Convert.FromBase64String(dataSet.Tables[0].Rows[0][fileContentsField].ToString());
                }
                else
                {
                    fileContent = (byte[])dataSet.Tables[0].Rows[0][fileContentsField];
                }
            }

        return new FileProviderInfo(this.File, lastModified, fileContent?.LongLength ?? 0);
        }


        protected override Stream DoOpenRead()
        {
            byte[] fileContent = new byte[0];

            string sql = string.Format(selectCommand, parentKey);
            var dataSet = DataServiceBase.ExecuteDataset(connectionString, CommandType.Text, sql);
            if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
            {                   
                if (mustBase64Decode)
                {
                    fileContent = Convert.FromBase64String(dataSet.Tables[0].Rows[0][fileContentsField].ToString());
                }
                else
                {
                    fileContent = (byte[])dataSet.Tables[0].Rows[0][fileContentsField];
                }
            }

            return new MemoryStream(fileContent);
        }

Reply to Thread

Enter the verification text